离子,上传图像或字符串firebase不工作在Android上,但在浏览器和iOS工作 [英] Ionic, upload image or string to firebase not working on Android, but working in browser and iOS
问题描述
因为大约3天,我试图上传一个图像到firebase存储没有成功。
我尝试了几种方法,我在这里找到了stackoverflow。
甚至不可能为Android上传一个简单的字符串。
在浏览器中运行应用程序对图像和字符串运行正常。
模拟器和手机返回相同的错误:
Firebase存储:发生未知错误,请检查服务器响应的错误有效负载。
我不知道应该在哪里查看提到的有效载荷
这是我上传字符串的代码:
编辑:I将检索错误的函数改为
alert(error.serverResponse);
错误信息:Multipart body does not contain
2或3部分
$ scope.upload = function(){
//存储引用
var storage = firebase.storage();
//路径引用
var storageRef = storage.ref();
var uploadTask = storageRef.child('testfile.png')。putString(any string)。then(function(snapshot){
console.log('upload successful');
警报('ok');
},函数(错误){
//处理不成功的上传
//alert(error.message);
alert(error.serverResponse );
});
下面添加的功能可以帮助您添加图片(文件是你想添加的图片)。
$ scope.addImage = function(file){
var fileRef = storageRef.child(file.name);
fileRef.put(file).then(function(snapshot){
console.log(snapshot)
});
};
since about 3 days I am trying to upload an image to the firebase storage without success.
I tried several approaches I found here in stackoverflow. It is even not possible to upload a simple string for Android.
Running the app in the browser is working fine for images and strings.
Emulator and phone returns the same error: Firebase Storage: An unknown error occurred, please check the error payload for server response.
I don't know where should I check the mentioned "payload"
This is my code for uploading the string: EDIT: I changed the function which retrieves the error to
alert(error.serverResponse);
this returns following Error message: "Multipart body does not contain 2 or 3 parts"
$scope.upload = function() {
//storage reference
var storage = firebase.storage();
//path reference
var storageRef = storage.ref();
var uploadTask = storageRef.child('testfile.png').putString("any string").then(function(snapshot) {
console.log('upload successful');
alert('ok');
}, function (error) {
// Handle unsuccessful uploads
//alert(error.message);
alert(error.serverResponse);
});
The function added below can help you to add an image on firebase where(file is the image you wish to add ).
$scope.addImage = function(file){
var fileRef = storageRef.child(file.name);
fileRef.put(file).then(function (snapshot) {
console.log(snapshot)
});
};
这篇关于离子,上传图像或字符串firebase不工作在Android上,但在浏览器和iOS工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!