将文件从 Azure VM 上传到 Azure 存储

Upload files to Azure Storage from Azure VM

我在 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 上成功读取文件。所以可能不是本地权限问题。

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