我正在尝试将图像从我的 Cordova 应用程序上传到新的 Firebase 存储。这是我迄今为止所尝试的。
// Get the image from PhotoLibrary
navigator.camera.getPicture(onSuccess, onFail, {
quality: quality,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
destinationType: Camera.DestinationType.FILE_URI,
targetWidth: imageSize,
targetHeight: imageSize
});
function onSuccess(imageData) {
var storageRef = firebase.storage().ref();
window.resolveLocalFileSystemURL(imageData,
function(fileEntry) {
fileEntry.file(function(file) {
var uploadTask = storageRef.child('images/test.jpg').put(file);
uploadTask.on('state_changed', function(snapshot){
console.log(snapshot);
});
}
)
};
这会导致以下错误
FirebaseError: Firebase Storage: Invalid argument in `put` at index 0: Expected Blob or File.
我尝试过的另一件事是将图像获取为 base64 并转换为 Blob,但结果相同。
有谁知道如何获取 Firebase 存储所需的 Javascript 文件或 Blob 格式的图像?谢谢!