【问题标题】:Upload files to Azure Storage from Azure VM从 Azure VM 将文件上传到 Azure 存储
【发布时间】:2017-01-04 13:57:58
【问题描述】:

我在 Node.JS 中有一些代码从用户那里获取文件并将其上传到我的 blob 存储中。

我正在使用带有此代码的azure-storage 包:

blobSvc.createBlockBlobFromLocalFile('t-uploads', 'high/' + file.name, './tmp/storage/' + file.name, function(error, result, response) {
            console.log("did come here", error, result, response);
            if (!error) {
                console.log(response);
                fs.unlink('./tmp/storage/' + file.name);
            } else {
                console.log(error);
                next(new Error("Azure High Resolution Error!"));
            }
        });

问题是,当我从 c9.io 运行代码时,该代码可以工作,但当我在我的 azure VM 上使用相同的代码时,代码无法运行。

日志(来自 Azure VM):

trumptcore-2 at auth
trumptcore-2 upload authed
trumptcore-2 at rename: baracuda new.jpg
trumptcore-2 after remote
trumptcore-2 { files: { files: [ [Object] ] }, fields: {} }
trumptcore-2 { container: 'storage',
trumptcore-2   name: '3736f0ab_baracuda new.jpg',
trumptcore-2   type: 'image/jpeg',
trumptcore-2   originalFilename: 'baracuda new.jpg',
trumptcore-2   size: 30065 }
trumptcore-2 it is image
trumptcore-2 outside resize
trumptcore-2 Web server listening at: http://0.0.0.0:3000
trumptcore-2 Browse your REST API at http://0.0.0.0:3000/explorer

没有错误,但我的节点 api 重新启动

日志(来自 c9.io):

Web server listening at: http://0.0.0.0:8080
Browse your REST API at http://0.0.0.0:8080/explorer
at auth
upload authed
at rename: baracuda.jpg
after remote
{ files: { files: [ [Object] ] }, fields: {} }
{ container: 'storage',
  name: 'e1ddeb85_baracuda.jpg',
  type: 'image/jpeg',
  originalFilename: 'baracuda.jpg',
  size: 30400 }
outside resize
{ isSuccessful: true,
  statusCode: 201,
  body: '',
  headers: 
   { 'transfer-encoding': 'chunked',
     'content-md5': 'NwLTR4gRnN/6GyPETR5MWw==',
     'last-modified': 'Sun, 28 Aug 2016 11:33:43 GMT',
     etag: '"0x8D3CF372A628D41"',
     server: 'Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0',
     'x-ms-request-id': '65eb3380-0001-00a5-2020-01fdd4000000',
     'x-ms-version': '2015-12-11',
     'x-ms-request-server-encrypted': 'false',
     date: 'Sun, 28 Aug 2016 11:33:43 GMT',
     connection: 'close' },
  md5: undefined }
{ isSuccessful: true,
  statusCode: 201,
  body: '',
  headers: 
   { 'transfer-encoding': 'chunked',
     'content-md5': 'bX2AWHEjxMY2r5yta2ChIQ==',
     'last-modified': 'Sun, 28 Aug 2016 11:33:43 GMT',
     etag: '"0x8D3CF372A90378B"',
     server: 'Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0',
     'x-ms-request-id': 'e1cbc742-0001-010a-3f20-019911000000',
     'x-ms-version': '2015-12-11',
     'x-ms-request-server-encrypted': 'false',
     date: 'Sun, 28 Aug 2016 11:33:43 GMT',
     connection: 'close' },
  md5: undefined }

更新

我在失败的地方尝试了这段代码

fs = require('fs')
        fs.readFile('./tmp/storage/' + file.name, 'utf8', function (err,data) {
          if (err) {
            return console.log(err);
          }
          console.log(data);
        });

因此,我可以在 azure vm 和 c9.io 上成功读取文件。所以可能不是本地权限问题。

【问题讨论】:

  • 您是否遇到任何错误?你能分享这些错误细节吗?
  • @GauravMantri 添加日志请检查

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


【解决方案1】:

好的,很抱歉给您带来麻烦,上传完成后,是愚蠢的 pm2 重新启动了我的应用程序。

【讨论】:

    猜你喜欢
    • 2020-10-29
    • 2020-08-18
    • 2020-01-03
    • 2020-11-11
    • 2017-05-06
    • 1970-01-01
    • 2020-09-04
    • 2021-03-07
    • 2021-04-04
    相关资源
    最近更新 更多