【发布时间】:2018-08-01 14:50:44
【问题描述】:
我的 ionic android 应用程序出现错误。使用与我的 ios 应用程序完全相同的代码(具有两个平台的 ionic:android 和 ios),我无法将 base64 uri 发送到 Firebase storage。
错误是:
Uncaught TypeError: mountainImagesRef.putString is not a function
at navigator.camera.getPicture.quality (controllers.js:202)
at Object.callbackFromNative (cordova.js:294)
at <anonymous>:1:9
我在这里看到了类似的东西,但解决方案是更新插件,我已经在使用cordova-plugin-camera 的最新版本:V 4.0.3。
Uncaught TypeError: ref.putString is not a function
在我的 ios 应用程序中,.putString() 功能正在运行!如何在我的 android 应用程序上进行这项工作?你看到我做错了什么吗?我尝试了很多方法来使用putString,比如uri.substring(0,23)...等。
function takePic()
{
navigator.camera.getPicture(
function(uri){
$ionicPopup.alert({
title: 'A new image',
template: 'Loading !'
});
// Create a root reference
var storageRef = firebase.storage().ref();
var filename = Math.floor((Math.random()*10000)+ 1);
var newAvatar_name = filename+".jpg";
var mountainImagesRef = storageRef.child("avatars/"+newAvatar_name);
mountainImagesRef.putString(uri, "base64").then(function(snapshot) {
console.log("Uploaded a base64 string!");
});
},
function(){
$ionicPopup.alert({
title: 'Error',
template: 'impossible to select one'
});
},
{
quality: 60,
targetHeight: 300,
targetWidth: 300,
destinationType: 0,
sourceType: 1,
mediaType: 0,
saveToPhotoAlbum: false
}
);
}
【问题讨论】:
-
在这里查看我的答案=> stackoverflow.com/a/51471159/1081909
-
感谢您的回复,但我已经尝试改变我使用
putString()的方式,但问题似乎是putString()未知...另外,用你的方法我收到此错误:window.resolveLocalFileSystemURL is not a function
标签: javascript cordova