javascript - 无法使用 Node.js SDK 下载文件夹内的 blob

标签 javascript node.js azure azure-blob-storage

我正在尝试下载 Azure 中 Blob 容器中的一些 Blob。

当文件位于根容器上时我成功,但当文件位于文件夹内时则失败。

const folder = 'AZURE_FOLDER';

const filesToDownload =  [ 'icon.ico', 'images/cover.jpg', 'images/htmlstructure.png' ]

filesToDownload.forEach(blob => {
      service.download(containerName, blob, `${folder}/${blob}`)
});

运行此代码,下载的文件是“icon.ico”,但我收到此错误的所有其他文件:

error : { Error: ENOENT: no such file or directory, open 'AZURE_FOLDER/images/cover.jpg'

error : { Error: ENOENT: no such file or directory, open 'AZURE_FOLDER/images/htmlstructure.png'

我的 listBlob 响应:

BlobResult {
  name: 'images/cover.jpg',
  creationTime: 'Wed, 03 Apr 2019 17:14:03 GMT',
  lastModified: 'Wed, 03 Apr 2019 17:14:03 GMT',
  etag: '0x8D6B857C5B2B355',
  contentLength: '299040',
  contentSettings: 
   { contentType: 'image/jpeg',
     contentEncoding: '',
     contentLanguage: '',
     contentMD5: 'JqJRnPltEsAhar+YfKgEtQ==',
     cacheControl: '',
     contentDisposition: '' },
  blobType: 'BlockBlob',
  accessTier: 'Hot',
  accessTierInferred: true,
  lease: { status: 'unlocked', state: 'available' },
  serverEncrypted: 'true' }
BlobResult {
  name: 'images/htmlstructure.png',
  creationTime: 'Wed, 03 Apr 2019 17:14:02 GMT',
  lastModified: 'Wed, 03 Apr 2019 17:14:02 GMT',
  etag: '0x8D6B857C4ECA732',
  contentLength: '65835',
  contentSettings: 
   { contentType: 'image/png',
     contentEncoding: '',
     contentLanguage: '',
     contentMD5: 'uHsFKqK9csssX0XYt86dlA==',
     cacheControl: '',
     contentDisposition: '' },
  blobType: 'BlockBlob',
  accessTier: 'Hot',
  accessTierInferred: true,
  lease: { status: 'unlocked', state: 'available' },
  serverEncrypted: 'true' }
BlobResult {
  name: 'user.ico',
  creationTime: 'Wed, 03 Apr 2019 16:58:24 GMT',
  lastModified: 'Wed, 03 Apr 2019 16:58:33 GMT',
  etag: '0x8D6B8559B5CC9C8',
  contentLength: '179677',
  contentSettings: 
   { contentType: 'image/x-icon',
     contentEncoding: '',
     contentLanguage: '',
     contentMD5: 'sHZ3nvd9fyX09EkqQvDvLQ==',
     cacheControl: '',
     contentDisposition: '' },
  blobType: 'BlockBlob',
  accessTier: 'Hot',
  accessTierInferred: true,
  lease: { status: 'unlocked', state: 'available' },
  serverEncrypted: 'true' }

最佳答案

AZURE_FOLDER/images 目录是否存在?如果没有,您需要事先使用 fs 模块创建它。

关于javascript - 无法使用 Node.js SDK 下载文件夹内的 blob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55502208/

相关文章:

c# - Azure B2C 身份验证(Angular + .net core Web API)- 不记名 token 中未找到范围或角色声明

javascript - 如何强制 jQuery UI 对话框再次重绘或触发某些内容强制调整大小

javascript - 为什么 BrowserRouter 和 Route from 'react-router-dom' 无法正常工作?

c++ - 如何从 node-gyp 定位 'imqi.hpp'

node.js - Mongoose : "TypeError: Undefined type at"

azure - 如何改进 Azure SQL 数据仓库中单个用户的查询执行并行化?

javascript - 如何渲染没有数据的部分

javascript - 通过js函数更改全局变量

node.js - 如何下载电子邮件附件 Node js

azure - 使用历史记录模式在 Azure 应用服务上部署 Vue CLI