如何将文件放在firebase存储中的离子

编程入门 行业动态 更新时间:2024-10-23 22:26:32
本文介绍了如何将文件放在firebase存储中的离子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用cordovaCamera插件在我的离子应用程序中获取文件URL。

I am using cordovaCamera plugin to get file url in my ionic app.

我希望将此文件放在firebase存储而不是base64 。

I wish to put this file on firebase storage not as 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") });

推荐答案

为了使其有效,您需要使用 destinationType:Camera.DestinationType.FILE_URI 获取图片的网址。

In order to make it works you will need to use destinationType: Camera.DestinationType.FILE_URI to get the URL of the image.

然后,您可以获得Blob来自此图像的 cordova-plugin-file (不要忘记添加它)并将其发送到Firebase。

Then, you can get the Blob from this image with cordova-plugin-file (don't forget to add it) and send it to Firebase.

此代码可能有语法错误我将其从Ionic 2代码转换。

This code could have syntax mistake I am converting it from Ionic 2 code.

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

更多推荐

如何将文件放在firebase存储中的离子

本文发布于:2023-11-24 09:11:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1624605.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:放在   如何将   离子   文件   firebase

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!