简体   繁体   中英

Upload files to Azure Storage from Azure VM

I have some code in Node.JS that takes file from user and uploads it to my blob storage.

I am using azure-storage package with this code:

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!"));
            }
        });

the thing is that the code works when i run it from c9.io but does not run when I use the same code on my azure VM.

log (from 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

no errors as such but my node api restarts

log (from 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 }

Update

i tried this code at location where it all fails

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

I can hence read the files successfully on both azure vm and c9.io. so probably not permissions issue on local.

不好意思,抱歉,上载完成后,正是哑巴pm2重新启动了我的应用程序。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM