0

我正在使用cordovaCamera插件在我的离子应用程序中获取文件的URL。如何把文件放在离子中的火力点存储

我想把这个文件放在firebase storage 不是base64

这里是我的参考

$cordovaCamera.getPicture(options) 
.then(function(imageData) { 
var pthref = firebase.storage().ref().child("a/b"); 
pthref.put(WHAAT SHOULD GO HERE).then(function(snapshot) { 
alert('file uploaded!'); 
}, 
function(a) 
{ 
alert("error"+JSON.stringify(a))}); 
}, 
function(err) { 
alert("Camera Error") 
}); 
+0

“imageData”看起来是最合乎逻辑的一个。它不工作? –

+0

imageData返回文件的路径。我需要把Blob或文件对象 – sam

回答

0

为了使其运作的,你需要使用destinationType: Camera.DestinationType.FILE_URI来获得图像的URL代码。

然后,您可以使用cordova-plugin-file(不要忘记添加它)并将其发送到Firebase,从此图像中获取Blob。

此代码可能有语法错误,我将它从Ionic 2代码转换而来。

var options = { 
    destinationType: Camera.DestinationType.FILE_URI 
}; 
$cordovaCamera.getPicture(options) 
    .then(function (fileUrl) { 
     window.resolveLocalFileSystemURL(fileUrl, (fileEntry) => { 
      fileEntry.file((file) => { 
       let reader = new FileReader(); 
       reader.onloadend = function() { 
       let imgBlob = new Blob([ this.result ], { type: "image/jpeg" }); 
       // Send file to firebase here 
       var pthref = firebase.storage().ref().child("a/b"); 
       pthref.put(imgBlob); 
       }; 
       reader.onerror = (error) => { 
       console.error(error); 
       }; 
       reader.readAsArrayBuffer(file); 
      }, (error) => { 
       console.error(error); 
      }); 
     }) 
    }, 
    function (err) { 
     alert("Camera Error") 
    }); 
+0

我正在开发ionic1。更多'cordova-plugin-file'无法解析IOS中的路径。我不能使用这个插件。我使用destinationType FILE_URI – sam

相关问题