Ste*_*tar 7 firebase ionic2 firebase-storage angular
我的离子2应用程序中有一个简单的功能,可以将文件上传到我的firebase存储服务器.它从相机中抓取base64编码的图像字符串,但是当我不尝试强制它时content-type
,它默认为application/octet-stream
.当我尝试将元数据添加到putString()
方法时,我收到错误.
有谁知道我怎么能这样做putString
?
这是我目前的功能:
uploadProfilePhoto(file) {
this.storage.get('user').then(user => {
let id = user.id;
var metadata = {
contentType: 'image/jpeg',
};
let userProfileRef = this.fbStorage.ref(`/users/${id}/profile_photo/profile_photo.jpg`);
userProfileRef.putString(file, metadata).then(snapshot => {
}).catch(error => {
});
})
}
Run Code Online (Sandbox Code Playgroud)
所以有了这个,我错过了一个参数来指定base64.这是更新的功能:
uploadProfilePhoto(file) {
this.storage.get('user').then(user => {
let id = user.id;
var metadata = {
contentType: 'image/jpeg',
};
let userProfileRef = this.fbStorage.ref(`/users/${id}/profile_photo/profile_photo.jpg`);
userProfileRef.putString(file, 'base64', metadata).then(snapshot => {
}).catch(error => {
});
})
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1818 次 |
最近记录: |