![](/img/trans.png)
[英]Upload AJAX response (image blob) to Azure Blob Storage: Error 414
[英]Cannot view image upload to azure blob storage
我正在使用Node.js將圖像上傳到Azure存儲https://github.com/Azure/azure-storage-node 。 上載成功,但是訪問URL時看不到圖像。
上傳代碼如下所示。
var file = 'tmp/myimage.png';
var blobService = azure.createBlobService(config.azure.connection_string);
blobService.createBlockBlobFromLocalFile(config.azure.container, 'taskblob', file, function(err, result, response) {
if(err) return console.log(err);
console.log(response);
callback();
});
在azure門戶中,我可以看到某些內容已上傳到我的容器中,訪問提供的URL只會加載一個空白頁面。
https://<storage>.blob.core.windows.net/<container>/taskblob
登錄“響應”時,我也從Azure得到了成功響應
@wazzaday,通常,我們可以使用提供的代碼將文件上傳到Azure Blob Stroage。
var azure = require('azure-storage');
var blobSvc = azure.createBlobService("**","**");
var file = 'tmp/1.txt';
blobSvc.createContainerIfNotExists('mycontainer', function (error, result, response) {
if (!error) {
// Container exists and allows
// anonymous read access to blob
// content and metadata within this container
console.log('ok')
}
});
blobSvc.createBlockBlobFromLocalFile('mycontainer', 'myblob1', file, function (error, result, response) {
if (!error) {
console.log('file uploaded'+response)
} else {
console.log(error);
}
});
從上面的代碼中,我們需要確保文件路徑正確。 由於您在Azure Portal上的文件大小為0,因此建議您嘗試使用ReadStream上傳文件並再次檢查文件大小。 請參考以下代碼:
var azure = require('azure-storage');
var fs = require('fs');
var blobSvc = azure.createBlobService("**","**");
var file = 'tmp/1.txt';
var stream = fs.createReadStream(file)
var dataLength = 0;
// using a readStream that we created already
stream
.on('data', function (chunk) {
dataLength += chunk.length;
})
.on('end', function () { // done
console.log('The length was:', dataLength);
});
blobSvc.createContainerIfNotExists('mycontainer', function (error, result, response) {
if (!error) {
// Container exists and allows
// anonymous read access to blob
// content and metadata within this container
console.log('ok')
}
});
blobSvc.createBlockBlobFromStream('mycontainer', 'filename', stream,dataLength, function (error) {
if (!error) {
console.log('ok Blob uploaded')
}
});
請嘗試上面的代碼,任何更新,請讓我知道。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.