我的 ionic 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 => {
});
})
}
因此,我缺少一个指定 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 => {
});
})
}