Blob 파일을 Firebase에 업로드하려고하는데 "makeFileIntoBlob"함수가 반환되면서 "undefined"가 계속 나타납니다. Android에서 실행 중입니다. 사진을 찍은 후 파일 경로를 가져올 수 있지만 Blob을 검색하여 Firebase에 업로드하는 기능을 호출하면 Blob 파일이 "정의되지 않은"파일이됩니다. 몇 도와달라고? Heres는Ilob 용 TypeScript on Blob에 파일 만들기
내가 그림
촬영 기능을 HeresmakeFileIntoBlob(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());
};
FilePath를
에서의 Blob를 만들기 위해 노력하고 어디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);
});
});
}
Heres는 중포 기지 저장하는 기능을 이미지를 업로드 기능
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'를 사용하고 있기 때문에 이것은 [Javascript Promises with FileReader()] (https://stackoverflow.com/questions/34495796/javascript-promises-with-filereader)와 중복 될 수 있습니다. 콜백을 사용하여 '약속'을 해결하거나 거부하지 않습니다. – jcalz