node.js - 如何从 node.js 中的 blobService.getBlobToStream 返回结果?
问题描述
我正在尝试将 excel 存储在 azure blob 中。我成功地将文件读入文件' testing.xlsx '。现在,我想用这个excel文件(' testing.xlsx ')出来blobService.getBlobToStream()
,但是做不到。
blobService.getBlobToStream(container, blobname, fs.createWriteStream('testing.xlsx'), function (error, result) {
if(!error) {}
});
解决方案
我尝试使用以下节点包编写示例代码azure-storage
,然后成功运行它,没有任何错误将我的 blob 下载到 excel 文件testing.xlsx
。
var azure = require('azure-storage');
var fs = require('fs');
var accountName = '<storage account name>';
var accountKey = '<storage account key>';
var blobService = azure.createBlobService(accountName, accountKey);
var containerName = 'test';
var blobName = 'testing.xlsx';
var localFileName = 'testing.xlsx';
var writable = fs.createWriteStream(localFileName);
blobService.getBlobToStream(containerName, blobName, writable, function(error, result) {
if(error) {
console.log(error)
}else{
console.log(result)
}
})
它的结果和截图如下。
所以不知道你遇到了什么问题。如果您收到任何错误信息或其他任何错误信息,请更新您的帖子,让我知道以寻求帮助。
更新:
var writable = fs.createWriteStream(localFileName);
blobService.getBlobToStream(containerName, blobName, writable, function(error, result) {
if(error) {
console.log(error)
}else{
console.log(result)
}
fs.readFile(localFileName, function(err, data) {
if(err) {
console.error(err);
}
console.log(data);
});
})
推荐阅读
- python - PyQt4 QSlider groove color customization
- nginx - 使用 apollo 客户端从 nextjs 中的 getInitialProps 方法执行 graphQL 查询时 ECONNREFUSED
- php - CI 导出 CSV 数据格式问题
- javascript - 在 howler.js 项目中使用 js 设置输入范围滑块最大属性
- python - I tried to make a daylight cycle in my game, but once it turns to night it will not go back to day
- javascript - Change multiple date values with jQuery
- sql - 如何根据另一条记录是否不存在来选择记录?
- php - 空数据添加到 PHP 中的文本文件
- docker - docker-compose 连接到其他容器失败
- c# - 测试具有外部依赖项的 C# 类库