0

因爲大約3天我試圖上傳圖像到firebase存儲沒有成功。離子,上傳圖片或字符串到firebase不工作在Android上,但在瀏覽器和iOS工作

我嘗試了幾種在stackoverflow中找到的方法。 甚至不可能爲Android上傳簡單的字符串。

在瀏覽器中運行應用程序對圖像和字符串運行正常。

模擬器和手機返回相同的錯誤: Firebase存儲:發生未知錯誤,請檢查服務器響應的錯誤有效負載。

我不知道我應該檢查所提到的「有效載荷」

這是我上傳的串碼: 編輯:我改變了檢索錯誤

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

回答

0

下面添加的功能可以幫助您在Firebase中添加圖像,其中(文件是您希望添加的圖像)。

$scope.addImage = function(file){ 
    var fileRef = storageRef.child(file.name); 
    fileRef.put(file).then(function (snapshot) { 
      console.log(snapshot) 
     }); 
}; 
相關問題