Uploading files with PhoneGap + iPhone

2019-03-26 07:02发布

I understand that PhoneGap applications are largely (if not entirely) HTML5 + CSS + JavaScript. Natively, the iPhone doesn't provide controls to upload files.

Does PhoneGap provide any mechanisms that allow users to upload files? (images / video, in the case of the iPhone)

I know Titanium allows users to do this, but it's a different animal with its compiled Javascript and proprietary APIs. Thanks for your advice/input.

3条回答
成全新的幸福
2楼-- · 2019-03-26 07:34

You can do an xmlhttprequest to the file on a local drive.
I'm not 100% sure if it will work on the iPhone, but webkit should support it.

function getImageBinaries(url) { //synchronous binary downloader for firefox2

var req = new XMLHttpRequest();
req.open("GET", url, false);

req.overrideMimeType('text/plain; charset=x-user-defined');

req.send("");
if (req.status != 200) {
    return "";
}
var t = req.responseText || "" ;
var ff = [];
var mx = t.length;
var scc= String.fromCharCode;
for (var z = 0; z < mx; z++) {
    ff[z] = scc(t.charCodeAt(z) & 255);
}
var b = ff.join("");
return b;
}

Succes, Erik

查看更多
贪生不怕死
3楼-- · 2019-03-26 07:47

Check this post out (linking has changed since this was orignally posted): http://zacvineyard.com/blog/2011/03/upload-a-file-to-a-remote-server-with-phonegap

查看更多
叼着烟拽天下
4楼-- · 2019-03-26 07:48

I believe you might be able to read the files using the PhoneGap API and the upload them using and AJAX post if the server application supported it.

The other option is to write a custom module/Plugin in PhoneGap that could specific to your needs.

Here are some Example Plugins

查看更多
登录 后发表回答