我在一週前遇到過同樣的問題,我想出的唯一解決方案是編寫自己的代碼,通過http請求發送文件。隨意使用的例子:
function azureChangeFn() {
\t \t \t var inputElement = document.getElementById("fileSelect");
\t \t \t var newFile = inputElement.files[0];
\t \t \t var url = "https://YOUR_STORAGE_NAME.blob.core.windows.net/CONTAINER_NAME/"+ newFile.name +"GENERATED_SharedAccessSignature_FROM_AZURE_SITE";
\t \t \t
\t \t \t var xhr = new XMLHttpRequest();
\t \t \t xhr.addEventListener("progress", updateProgress);
\t \t \t xhr.onreadystatechange = function() {
\t \t \t \t if (xhr.readyState == XMLHttpRequest.DONE) {
\t \t \t \t \t alert("Sent to azure storage service!");
\t \t \t \t }
\t \t \t }
\t \t \t xhr.open('PUT', url, true);
\t \t \t xhr.setRequestHeader("Content-type", "multipart/form-data");
\t \t \t xhr.setRequestHeader("lng", "en");
\t \t \t xhr.setRequestHeader("x-ms-blob-type", "BlockBlob");
\t \t \t xhr.setRequestHeader("x-ms-blob-content-type", newFile.type);
\t \t \t xhr.send(newFile);
\t \t }
\t \t
\t \t function updateProgress (oEvent) {
\t \t if (oEvent.lengthComputable) {
\t \t \t var percentComplete = oEvent.loaded/oEvent.total;
\t \t \t console.log(percentComplete);
\t \t } else {
\t \t \t alert('FAIL');
\t \t }
\t \t }
<html>
<head>
</head>
<body>
\t \t <label>Example without library:</label>
\t \t <br>
\t \t <label>Select file: <input type="file" id="fileSelect" onchange="azureChangeFn()"></label>
\t \t
\t \t
</body>
</html>
談到NG-文件上傳庫,在源代碼中我發現,formData.append方法附加文件時,automaticaly增加了web的套件頭。據我瞭解,FormData用於POST方法,但是當使用PUT時,所有主體都被當作文件。很遺憾,我無法通過POST方法將文件上傳到Azure存儲。
你能提供一個用來下載文件的代碼嗎? –