gpt4 book ai didi

javascript - Ionic 3 + Firebase Storage 获取个人资料图片

转载 作者:行者123 更新时间:2023-11-30 21:03:38 27 4
gpt4 key购买 nike

我有这个代码:

/////////////////////////////////////////////CROP + UPLOAD FOR FIREBASE STORAGE//////////////////////////

// Return a promise to catch errors while loading image
getMedia(): Promise<any> {
// Get Image from ionic-native's built in camera plugin
return Camera.getPicture(this.options)
.then((fileUri) => {
// Crop 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 fileUri
} else if (this.platform.is('android')) {
// Modify fileUri format, may not always be necessary
fileUri = 'file://' + fileUri;
/* Using cordova-plugin-crop starts here */
return Crop.crop(fileUri, { quality: 100 });
}
}).then((path) => {
// path looks like 'file:///storage/emulated/0/Android/data/com.foo.bar/cache/1477008080626-cropped.jpg?1477008106566'
// console.log('Cropped Image Path!: ' + path);
path; // return the path of file
window.resolveLocalFileSystemURL(path, FE=>{
FE.file(file=>{
const FR=new FileReader()
FR.onloadend = ((res: any)=>{
let AF=res.target.result
let blob=new Blob([new Uint8Array(AF)], {type: 'image/jpg'});
this.upload(blob)
});
FR.readAsArrayBuffer(file);
})
})
})
}

upload(blob:Blob){
const currentUserId = this.fire.auth.currentUser.uid; // get user UID in firebase
this.Fbref.child(`Profile/${currentUserId}/img`).put(blob); //path in firebase storage


////GET Image URL
this.Fbref.child(`Profile/${currentUserId}/img` ).getDownloadURL().then(function(url){
console.log("the URL Image is: " + url);
url;
let photoURL = this.url

});}

它工作完美,图像剪切然后上传....但我无法将图像的 URL 保存在 Firestore 数据库的用户配置文件 DOC 中。

需要作为photoURL: (URL Image)

有人知道怎么做吗?

最佳答案

[已解决]添加下面的代码效果很好

savephotoURL(){
const currentUserId = this.fire.auth.currentUser.uid;
this.Fbref.child(`Profile/${currentUserId}/img` ).getDownloadURL().then(function(url){
console.log("the URL Image is: " + url);
let imageURL = url
return imageURL
}).then((imageURL) => {
this.database.doc(`ProfileUser/${currentUserId}/`).update({photoURL:imageURL}) })// save url in Firestore database realtime
}

关于javascript - Ionic 3 + Firebase Storage 获取个人资料图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46864505/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com