1

firebase cloud機能にfiles(images)をアップロードしようとしています。Node.js firebase storageに画像をアップロード

const storage = require('@google-cloud/storage')(); 
var bucket = storage.bucket('myBucketName'); 
var buffer = bufferRepresentMyImage; 
// what next? 

私はGCP's APIから次のコードが見つかりました::しかし

bucket.upload(filename, (err, file) => { 
    // code goes here 
}); 

を多くの記事を読んだ後、私はこれを行うことができる唯一の方法は、Google Cloud Platform (GCP) APIを使用することであり、ここでは私のコードであることがわかりましたそれはファイルのデータを要求しないので動作しないと思われ、代わりにcallback functionfileを返します。誰でもimagebucketをアップロードする方法を教えてください。

+0

https://firebase.google.com/docs/storage/extend-with-functionsをご覧ください。 – gokcand

答えて

0

リモートの宛先ファイル名は、オプションのparamに含まれています。あなたの例(およびこの回答)のfilenameは、ローカルのファイル名のパスです。

let options = { 
     destination: fileNameOnDestinationBucket, 
     metadata: {     // (optional) 
      metadata: yourCustomMetadata, 
      contentType: 'image/jpeg' // (example) 
     } 
    }; 

// with Promise: 
bucket.upload(filename, options).then((response)=>{ 
    ... 
}); 

// with callback: 
bucket.upload(filename, options, (err, metadata, response)=>{ 
.... 
}); 
関連する問題