Ionic, upload image or string to firebase not working on Android, but working in browser and iOS

假如想象 提交于 2019-12-25 08:50:01

问题


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);
                        });

回答1:


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)
       });
};


来源:https://stackoverflow.com/questions/40357848/ionic-upload-image-or-string-to-firebase-not-working-on-android-but-working-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!