2014-01-20 4 views
0

내 응용 프로그램에 CompoundJS를 사용하고 있는데 이제는 compoundjs에서 azure blob에 이미지를 업로드하는 스크립트를 구현하려고합니다.NodeJS (CompoundJS)를 사용하여 azure 컨테이너에 BLOB 업로드

웹을 검색 한 결과 this link에 지정된대로 azure (하늘색 설치) 이 있음을 확인했습니다.

다음은

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

스토리지 액세스 자격 증명을 제공하는 방법은 여러 가지가 있습니다. 환경 변수를 사용하여 계정 이름과 키를 설정하고 있습니다. 여기

내가 bash는 사용하여 환경 변수를 설정하는 방법입니다

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 

을 그리고 여기 샘플 내가 ImageMagick과를 사용하여, 하늘빛의 모양으로 저장되어있는 기존의 이미지 썸네일을 생성하는 데 사용할 스크립트를 Node.js를 수 있습니다 :

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

관련 문제