无法查看上传到Azure Blob存储的图像 [英] Cannot view image upload to azure blob storage

查看:165
本文介绍了无法查看上传到Azure Blob存储的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Node.js将图像上传到Azure存储器 https://github.com/Azure/azure-storage-node .上传成功,但是访问URL时看不到图像.

I am using Node.js to upload an image to azure storage https://github.com/Azure/azure-storage-node. The upload is successful, but I cannot see the image when I visit the 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只会加载一个空白页面.

In azure portal I can see something has been uploaded to my container, visiting the provided URL just loads a blank page.

https://<storage>.blob.core.windows.net/<container>/taskblob

在登录响应"时,我也收到了Azure的成功响应

I am also getting a success response back from Azure when logging 'response'

推荐答案

@wazzaday,通常,我们可以使用提供的代码将文件上传到Azure Blob Stroage.

@wazzaday, Generally, we can upload the files into Azure Blob Stroage using the code as you provided.

    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上载文件并再次检查文件大小.请参考此代码:

From above code, we need make sure the file path is right. Because your file size is 0 on Azure Portal, I suggest you can try ReadStream to upload your file and check the file size again. Please refer to this code :

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')
    }

});

请尝试上面的代码,如有任何更新,请告诉我.

Please try above code, any update, please let me know.

这篇关于无法查看上传到Azure Blob存储的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆