2014-01-20 3 views
0

Я использую CompoundJS для своего приложения и теперь пытаюсь реализовать скрипт, который будет загружать изображения в azure blob от complexjs.Загрузить blob в windows azure container с помощью NodeJS (CompoundJS)

Я искал веб-сайт и обнаружил, что есть модуль azure (npm install azure) , как указано в this link.

Ниже приведен фрагмент кода я использовал в моем приложении

var azure = require("azure"); 
var blobService = azure.createBlobService(); 
blobService.createContainerIfNotExists('container_name', {publicAccessLevel : 'blob'}, function(error){ 
    if(!error){ 
     // Container exists and is public 
     console.log("Container Exists"); 
    } 
}); 

Я знаю, что я должен настроить ACCESS KEY некоторые, где сделать эту работу, но не знаю, где.

Просьба предложить.

ответ

0

Существует несколько способов предоставления учетных данных доступа к хранилищу. Я использую переменные среды для установки имени учетной записи и ключа.

Вот как я установить переменные окружения, используя Баш:

echo Exporting Azure Storage variables ... 

export AZURE_STORAGE_ACCOUNT='YOUR_ACCOUNT_NAME' 

export AZURE_STORAGE_ACCESS_KEY='YOUR_ACCESS_KEY' 

echo Done exporting Azure Storage variables 

А вот пример node.js скрипт, который я использую для создания эскизов из существующих изображений, которые хранятся в Azure сгустков, с помощью ImageMagick:

var azure = require('azure'); 
var im = require('imagemagick'); 
var fs = require('fs'); 
var rt = require('runtimer'); 
//Blobservice init 

var blobService = azure.createBlobService(); 

var convertPath = '/usr/bin/convert'; 

var identifyPath = '/usr/bin/identify'; 

global.once = false; 


var blobs = blobService.listBlobs("screenshots", function (error, blobs) { 

    if (error) { 
     console.log(error); 
    } 

    if (!error) { 
     blobs.forEach(function (item) { 

      if (item.name) { 

       if (item.name.length == 59) { 

        //Create the name for the thum     
        var thumb = item.name.substring(0, item.name.indexOf('_')) + '_thumb.png'; 
        if (!global.once) { 
         console.log(global.once); 
         var info = blobService.getBlobToFile("YOUR CONTAINER", item.name, item.name, 
          function (error, blockBlob, response) { 
           im.resize({ 
            srcPath: item.name, 
            dstPath: thumb, 
            width: 100, 
            height: 200 
           }, 
            function (err, sdout, stderr) { 
             if (err) throw err; 
             console.log("resized"); 
             //Delete the downloaded BIG one 
             fs.unlinkSync(item.name); 


             //Upload the thumbnail 
             blobService.putBlockBlobFromFile("YOUR CONTAINER", thumb, thumb, 
                 function (error, blockBlob, response) { 

                  if (!error) { 
                   console.log("blob uploaded: " + thumb); 
                   fs.unlinkSync(thumb); 
                  } 

                 }); 
            }); 

          }); 

         //DEBUG: Uncomment to test only with one file 
         //global.once = true; 

        } 


       } 
      } 
     }); 
    } 
}); 

А вот официальная ссылка на Лазурном модуль для узла (он содержит некоторые образцы):

Windows Azure Client Library for node