2017-01-25 14 views
1

サムネイル画像にContent-Typeを設定する必要があります。私は以下のように試しました。しかし、それは動作していません。まだ、ストリームとして格納します。サムネイル画像を設定するコンテンツタイプ

enter image description here

Azureの機能:

var Jimp = require("jimp"); 

module.exports = (context, myBlob) => { 

    // Read image with Jimp 
    Jimp.read(myBlob).then((image) => { 

     // Manipulate image 
     image 
      .resize(200, Jimp.AUTO) 
      .greyscale() 
      .getBuffer(Jimp.MIME_JPEG, (error, stream) => { 
       if (error) { 
        context.log(`There was an error processing the image.`); 
        context.done(error); 
       } 
       else { 
        context.log(`Successfully processed the image`); 
        stream.set("Content-Type", Jimp.MIME_JPEG); // here need to set the Content-Type 
        context.done(null, stream); 

       } 

      }); 

    }); 

}; 

function.json

{ 
    "bindings": [ 
    { 
     "name": "myBlob", 
     "type": "blobTrigger", 
     "direction": "in", 
     "path": "project2-photos-original/{name}", 
     "connection": "thumbnailfunction_STORAGE", 
     "dataType": "binary" 
    }, 
    { 
     "type": "blob", 
     "name": "$return", 
     "path": "project2-photos-thumbnail/{name}", 
     "connection": "thumbnailfunction_STORAGE", 
     "direction": "out" 
    } 
    ], 
    "disabled": false 
} 
index.json

私は質問NodeJs

var Jimp = require("jimp"); 

var express = require("express"); 
var app = express(); 

app.get("/my-dynamic-image", function(req, res){ 
    Jimp.read("lenna.png", function(err, lenna) { 
     lenna.resize(64, 64).quality(60).getBuffer(Jimp.MIME_JPEG, function(err, buffer){ 
      res.set("Content-Type", Jimp.MIME_JPEG); 
      res.send(buffer); 
     }); 
    }); 
}); 

app.listen(3000); 

に、このように同じ実装を見てきました:は、あなたがどのようにAzureの機能にContent-Typeを設定する方法を教えてもらえますか?

p.s.私はNodejsの開発者ではありません。

答えて

1

EDIT:

残念ながらノードのバインディングブロブ出力は、コンテンツタイプの設定をサポートしていません。 1つのオプションは、出力バインディングを削除し、必要な制御を与えるべきノード関数にazure storage sdkをネイティブで使用することです。

結合HTTPトリガーと出力を使用している場合:

急行様「のres」オブジェクトがcontent.resを介してアクセスすることができ、その代わりにstream.setのあなたは​​/context.res.typeをお勧めします。 getBufferコールバックで返されたstreamオブジェクトは、ストリームではなくバッファであり、http応答とは関係ありません。注意すべき

一つは、紺碧の機能がまだノードからのストリームを返すサポートしていないということです - あなたは全体のバッファ持っている必要があります。ここ

getBufferである(、幸運にも、getBufferを返すように見えます!)コールバック:

function(err, buffer){ 
    if (err) { 
     context.log("There was an error processing the image."); 
     context.done(err); 
    } 
    else { 
     context.log("Successfully processed the image"); 
     // set content type to Jimp.MIME_JPEG 
     context.res.type(Jimp.MIME_JPEG) 
     // send the raw response (don't apply any content negotiation) 
     context.res.raw(buffer); 
    } 
}); 
+0

希望 'buffer'は私の例ではなく' stream'でしょうか? – Sampath

+0

'getBuffer'はストリームではなくバッファを返しますので、混乱を最小限に抑えるように名前を変更しました。 –

+0

あなたは 'index.json'ファイルの内容でそれを行う方法を教えてください。その内容を取得して追加してください。その後、私はより良い画像を持っていきます。 – Sampath

関連する問題