BlobファイルをFirebaseにアップロードしようとしていますが、「makeFileIntoBlob」関数が返されるため「未定義」になっています。私はAndroid上でそれを実行しています。 私は写真を撮影した後にファイルパスを取得できますが、Blobを取得してFirebaseにアップロードする機能を呼び出すと、Blobファイルが「未定義」になります。 いくつかお困りですか?ファイルをIonicのTypeScriptのBlobに作成する
私はFirebaseストレージに画像をアップロード相続機能
uploadToFirebase(imageBlob) {
var fileName = 'sample.jpg';
return new Promise((resolve, reject) => {
var fileRef = firebase.storage().ref('Animais/' + fileName);
var uploadTask = fileRef.put(imageBlob);
uploadTask.on('state_changed', (snapshot) => {
console.log('snapshot progess ' + snapshot);
}, (_error) => {
reject(_error);
},() => {
// completion...
resolve(uploadTask.snapshot);
});
});
}
私はファイルパス
makeFileIntoBlob(imagePath) {
var reader = new FileReader();
reader.onloadend = (evt: any) => {
var imgBlob: any = new Blob(imagePath);
imgBlob.name = 'sample.jpg';
return imgBlob;
};
reader.onerror = (e) => {
console.log('Failed file read: ' + e.toString());
};
からブロブをしようと相続機能Iピクチャ
を取る相続機能takePic(){
let imageSource;
this.camera.getPicture({
destinationType: this.camera.DestinationType.FILE_URI,
sourceType: imageSource,
encodingType: this.camera.EncodingType.JPEG,
targetHeight: 640,
correctOrientation: true,
saveToPhotoAlbum : true
}).then((imagePath) => {
alert('got image path ' + imagePath);
// convert picture to blob
return this.makeFileIntoBlob(imagePath);
}).then((imageBlob) => {
alert('got image blob ' + imageBlob);
// upload the blob
return this.uploadToFirebase(imageBlob);
}).then((uploadSnapshot: any) => {
alert('file uploaded successfully ' + uploadSnapshot.downloadURL);
// store reference to storage in database
return this.saveToDatabaseAssetList(uploadSnapshot);
}).then((uploadSnapshot: any) => {
//alert('file saved to asset catalog successfully ');
}, (error) => {
alert('Error ' + (error.message || error));
});
実際にTypeScriptを使用していますか?コンパイラのエラーは何ですか? 'BLOB'とは何ですか? – jcalz
はい、Typescript、Ionic3。申し訳ありませんが、私は試していた、ちょうど一種のデバッグBLOBのために、すでにそれを編集しました。私はコンパイラのエラーを取得していない、私はちょうど "makeFileIntoBlob"関数の戻り値として "未定義"になっています。 –
これは、[FileReader()](https://stackoverflow.com/questions/34495796/javascript-promises-with-filereader)の[Javascript Promises]と重複している可能性があります。 'Promise'を解決/拒否するコールバックを使用しません。 – jcalz