简体   繁体   English

Azure Blob存储Node.js后端

[英]azure blob storage node.js backend

I'm following this article on how to upload a blob into a container. 我正在关注如何将Blob上传到容器中的这篇文章 This is what I've have 这就是我所拥有的

var azure = require('azure-storage');
var blobSvc = azure.createBlobServiceAnonymous('https://<storage-name>.blob.core.windows.net/');

exports.post = function(request, response) {
    console.log(request.files); // [1] 

    blobSvc.createBlockBlobFromLocalFile('dubfiles', 'myblob', request.files.file.name, function(error, result, response){
        if(!error){
             // file uploaded
             console.log(response); //[2]
             console.log(result); // [3]
        }
    });

};

[ 1 ] Logs this [ 1 ]记录此

   { file: 
       { domain: null, 
         _events: null,
         _maxListeners: 10, 
         size: 859552,
         path: 'D:\\local\\Temp\\155976e3a6b8e0aa871c5deee05af9f2',
         name: 'heuristic-serch.pdf', 
         type: 'application/pdf',
         hash: false, 
         lastModifiedDate: Tue Jun 23 2015 08:43:55 GMT+0000 (Coordinated Universal Time),
        _writeStream: { 
                         domain: null,
                         _events: null,
                         _maxListeners: 10,
                         path: 'D:\\local\\Temp\\155976e3a6b8e0aa871c5deee05af9f2',
                         fd: 3, 
                         writable: false, 
                         flags: 'w', 
                         encoding: 'binary',
                         mode: 438,
                         bytesWritten: 859552, 
                         busy: false,
                         _queue: [], 
                         _open: [Function], 
                         drainable: true, 
                         flush: [Function],
                         write: [Function],
                         end: [Function],
                         destroy: [Function],
                         destroySoon: [Function],
                         pipe: [Function], 
                         setMaxListeners: [Function],
                         emit: [Function], 
                         addListener: [Function],
                         on: [Function], 
                         once: [Function],
                         removeListener: [Function],
                         removeAllListeners: [Function],
                         listeners: [Function] },
                         open: [Function],
                         toJSON: [Function], 
                         write: [Function],
                         end: [Function], 
                         setMaxListeners: [Function],
                         emit: [Function],
                         addListener: [Function],
                         on: [Function], once: [Function],   
                         removeListener: [Function],
                         removeAllListeners: [Function],
                         listeners: [Function]
                } 
         }

[2] Logs no response to logs [2]日志无响应

[3] Logs no result to logs [3]没有结果记录到日志

The container is empty when I check on the azure management portal. 当我在Azure管理门户上检查时,该容器为空。

How can this be done correctly? 如何正确完成?

I'm now able to upload a blob to a container. 现在,我可以将Blob上传到容器中。 This is what I have 这就是我所拥有的

var azure = require('azure-storage');

exports.post = function(request, response) {
   var accountName = request.service.config.appSettings.STORAGE_ACCOUNT_NAME; // storage account name at appSettings
   var accountKey = request.service.config.appSettings.STORAGE_ACCOUNT_ACCESS_KEY; //storage account key at appSettings
   var host = accountName + '.blob.core.windows.net';
   var container = 'container_name';

   var blobSvc = azure.createBlobService(accountName, accountKey, host); 

   blobSvc.createContainerIfNotExists(container, {publicAccessLevel : 'blob'}, function(error, result, response){
       if(!error){
            console.log('no error occurred!'); // logs if no error occurred
            console.log(result); // logs false if container already exists
            console.log(response); // logs response including the etag
          //Container exists and allows 
          //anonymous read access to blob 
          //content and metadata within this container

          blobSvc.createBlockBlobFromLocalFile(container, request.files.file.name, request.files.file.path, function(error, result, response){
              if(!error){
                // file uploaded
                // console.log(error);
                console.log(response); // logs response
                console.log(result); // logs result
              }
          });
       }
    });
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure Blob 存储和 Node.js - Azure blob storage and Node.js 列出 Azure 中的 Blob 存储和读取流 Node.js - List blob from Azure Blob Storage and Readstream in Node.js 如何使用node.js作为后端和angularjs作为前端从azure blob存储中播放像facebook这样的视频 - how to play a video like facebook from azure blob storage using node.js as backend and angularjs as front end 使用 axios、Node.js 连接到 Azure Blob 存储 REST API - Connect to Azure Blob Storage REST API with axios, Node.js Node.js上传到Azure Blob存储问题 - Node.js upload to Azure Blob Storage issues 如何通过 node.js 中的@azure/storage-blob 在 blob 存储中获取文件的安全 url? - How to get secure url of File in blob storage via @azure/storage-blob in node.js? 如何修复Node.js azure blob以上传和下载azure blob存储中的文件 - How to fix Node.js azure blob to upload and download files in azure blob storage 使用 node.js &#39;@azure/storage-blob&#39; 包从 Azure-Storage 流式传输视频 - Stream a video from Azure-Storage by using node.js '@azure/storage-blob' package 如何使用Node.js SDK将Azure Blob存储中的Append Blob读取为字符串? - How can I read an Append Blob from Azure Blob Storage to a string with Node.js SDK? 如何通过Azure网站上的Node.js应用程序将大文件的上传流通过管道传输到Azure Blob存储? - How to pipe upload stream of large files to Azure Blob storage via Node.js app on Azure Websites?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM