What I'm looking for is a way to 'upload' an image in an offline web application. I'm hoping there is a way to store the selected image in the cache and then upload it when they have internet access again. Is something like this possible?
You can use HTML5 FileSystem to store an image file, it is implemented in many of browsers not all yet. And then you can upload an image file to server with HTTP POST message. And, it is safe to encode in image file in Base64 format when uploading by HTTP.
To check out the internet connection, you can use XMLHTTPRequest.
Is something like this possible?
...for small files.
You can load file data using the HTML5 File API, and post it to the server via AJAX. Not having a connection will return an HTTP status code that can be used to trigger some sort of storage mechanism.
localStorage has a limit of about 5MB, which is why I say "small files".
Web SQL Databases might be able to store more data, however it's no longer being maintained:
Beware. This specification is no longer in active maintenance and the Web Applications Working Group does not intend to maintain it further.
If you're trying to cache a small image or text file, it's possible to store it locally and poll for an internet connection.
If you're trying to allow users to upload Tolstoy, you should probably have them wait until they've got an active internet connection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With