开发者

Uploading files with PhoneGap + iPhone

开发者 https://www.devze.com 2023-01-27 17:28 出处:网络
I understand that PhoneGap applications are largely (if not entirely) HTML5 + CSS + JavaScript. Natively, the iPhone doesn\'t provide controls to upload files.

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 i开发者_JS百科ts compiled Javascript and proprietary APIs. Thanks for your advice/input.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号