我有这段代码,用于上传用相机拍摄或从照片库中获取的图像。上传发生并在此代码执行后成功:
// Return a promise to catch errors while loading image
getMedia(options, square, username): Promise<any> {
//this.storage.get('username').then((val) => {this.username = val; console.log(this.username + " getting usern34433245555555ame")});
// Get Image from ionic-native's built in camera plugin
return this.camera.getPicture(options)
.then((fileUri) => {
// op Image, on android this returns something like, '/storage/emulated/0/Android/...'
// Only giving an android example as ionic-native camera has built in cropping ability
if (this.platform.is('ios')) {
return this.crop.crop(fileUri, { quality: 10 });
} else if (this.platform.is('android')) {
// Modify fileUri format, may not always be necessary
fileUri = 'file://' + fileUri;
/* Using cordova-plugin-crop starts here */
return this.crop.crop(fileUri, { quality: 10 });
}
})
.then(newPath => {
console.log(newPath);
if(newPath) {
let fileName = newPath.substring(newPath.lastIndexOf("/") + 1, newPath.length);
let filePath = newPath.substring(0, newPath.lastIndexOf("/"));
this.file.readAsDataURL(filePath, fileName).then(data => {
//let strImage = data.replace(/^data:image\/[a-z]+;base64,/, "");
//this.file.writeFile(this.file.tempDirectory, "image.jpg", strImage);
//let blob = dataURItoBlob(data);
var dataURL = data;
console.log(username + " this is passed usernameeeeeeeeee ==");
let image : string = 'profilepicture.png',
storageRef : any,
parseUpload : any;
return new Promise((resolve, reject) => {
storageRef = firebase.storage().ref('/profile/' + username + '/' + image);
parseUpload = storageRef.putString(dataURL, 'data_url');
console.log(username + " username in promise !!!!!!");
console.log("got to storageref after");
parseUpload.on('state_changed', (_snapshot) => {
// We could log the progress here IF necessary
console.log('snapshot progess ' + _snapshot);
},
(_err) => {
reject(_err);
console.log(_err.messsage);
},
(success) => {
console.log(' was a suc cesssssss');
resolve(parseUpload.snapshot);
})
}).then(value => {
//this.af.list('/profile/' + self.username).push({ pic: image });
}).catch(function(error) {
console.log(error.message);
});
//let file
});
}
});
}
console.log(username + " username in promise !!!!!!");
的控制台输出是正确的,我相信正在使用正确的storageRef
。
上传的控制台输出是:
[20:35:56] console.log: Blue username in promise !!!!!!
[20:35:56] console.log: got to storageref after
[20:35:56] console.log: snapshot progess [object Object]
[20:35:57] console.log: snapshot progess [object Object]
[20:35:57] console.log: was a suc cesssssss
但是,当我查看firebase存储时,新文件夹和图像不存在。 firebase存储没有变化。为什么它实际上没有存储在存储中?
答案 0 :(得分:0)
storageRef = firebase.storage().ref('/profile/' + username + '/' + image);
应该是:
storageRef = firebase.storage().ref('/settings/' + username + '/' + image);
我一直在寻找错误文件夹中的上传内容。