PhoneGap - 存储图像,然后获得其base64编码数据 [英] PhoneGap - storing an image, then getting its base64encoded data

查看:158
本文介绍了PhoneGap - 存储图像,然后获得其base64编码数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用PhoneGap Camera API拍摄照片,并使用 destinationType.FILE_URI 存储它。这部分工作。我可以随后采取提供的路径并将其设置为HTML图像的src,并显示图像。

I am using the PhoneGap Camera API to take a picture and store it using destinationType.FILE_URI. This portion is working. I can subsequently take the path provided and set it as the src of an HTML image, and the image appears.

在代码中,我想抓取图像,将其转换为base64编码数据,并将其传输到服务器。这是问题所在。

Later in the code, I want to grab the image, convert it to base64encoded data, and transmit it to the server. This is where the problem is.

我得到 {code:5} ,表示它是无效的URI)在我的fail回调中使用时:

I am getting {"code" : 5} (which, according to this, means it's an invalid URI) in my fail callback when using:

fileSystem.root.getFile("content://media/external/images/media/4292", null, gotFileEntry, fail);

我不明白为什么我可以设置 img.src ,但是phoneGap不能使用相同的URI来查找文件?

I don't understand why I can set an img.src, but phoneGap can't use the same URI to find the file?

推荐答案

OS具有用于 content:// 协议的URI处理程序。 File API没有。但是,您可以将 content:// 类型URI转换为 FileEntry 。使用:

It is because the Android OS has a URI handler for the content:// protocol. The File API does not. However, there is a way for you to convert a content:// type URI into a FileEntry. Use:

window.resolveLocalFileSystemURI("content://media/external/images/media/4292", win, fail);

并且成功回调 win FileEntry

这篇关于PhoneGap - 存储图像,然后获得其base64编码数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆