9

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.

5
  • Check this post out (linking has changed since this was orignally posted): zacvineyard.com/blog/2011/03/…
    – zvineyard
    Apr 15, 2011 at 4:23
  • The iPhone now does provides a native control to upload images. Oct 24, 2013 at 18:34
  • Seriously? <input type="file" /> will work now as of iOS 7?
    – jocull
    Oct 24, 2013 at 18:39
  • Yeah. Even in iOS 6. It'll ask the user to either choose a picture from the Camera Roll or to take a new picture. Oct 24, 2013 at 18:47
  • This is news to me (I never upgraded past iOS 5). Thanks!
    – jocull
    Oct 24, 2013 at 20:09

2 Answers 2

9

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

3
  • Looks like that is about as close as it gets. Any idea if reading / POSTing files in this manner will overload the memory? Not sure if it tries to buffer the whole thing before it goes for it.
    – jocull
    Dec 1, 2010 at 3:38
  • i have no idea, haven't really tried before, but you could always writ a plugin, they are not that hard. I have written one to download code. All the source is posted here blog.clearlyinnovative.com/post/2056122828/… Dec 1, 2010 at 4:52
  • Interesting, I hadn't seen a plugin in action yet. Thanks for the link.
    – jocull
    Dec 1, 2010 at 14:48
-1

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

1
  • Yes, but then you have the binaries. you can then encode them into a base64 string and use that to upload the file. You can put the base64 into a field if you want to post it. Just don't forget to make a little change in your server side to decode it. It's better then making a <input type='file'/> as that isn't supported on all devices (including the iPhone). you can either post this data, or do a httprequest with it.
    – Erik
    Dec 1, 2010 at 15:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.