像这样使用JavaScript Azure存储客户端库:
function UploadImageToTemp(file) {
SendToServer2("GetSAS", "", "", function (sas) {
var blobUri = 'https://' + 'myApp' + '.blob.core.windows.net';
if (window.location.host === "localhost:43890" || window.location.host === "127.0.0.1:43890")
blobUri = "http://127.0.0.1:10000/devstoreaccount1/";
var blobService = AzureStorage.Blob.createBlobServiceWithSas(blobUri, sas);
var customBlockSize = file.size > 1024 * 1024 * 32 ? 1024 * 1024 * 4 : 1024 * 512;
blobService.singleBlobPutThresholdInBytes = customBlockSize;
var finishedOrError = false;
var speedSummary = blobService.createBlockBlobFromBrowserFile('imagetemp', file.name, file, { blockSize: customBlockSize }, function (error, result, response) {
finishedOrError = true;
if (error) {
console.log("Temp image upload failed");
} else {
console.log("Temp image upload succeeded");
}
});
//refreshProgress();
});
}
在“ SendToServer”调用中,从云应用程序请求SAS令牌。快速检查我们是否在模拟器中本地运行,然后从Azure站点(here)复制并粘贴其余代码。
对blobService.createBlockBlobFromBrowserFile
的呼叫导致:
HTTP400: BAD REQUEST - The request could not be processed by the server due to invalid syntax.
(XHR)OPTIONS - http://127.0.0.1:10000/devstoreaccount1/imagetemp/barry.jpg?sv=2017-04-17&sr=c&sig=3R8NNe%2BA%2BLs1ZhIxMXevH%2FW7jvvkvYVYHKRZz67SWBg%3D&se=2018-10-18T19%3A26%3A06Z&sp=rwl&api-version=2018-03-28
有什么主意我做错了吗?