Hi,
I have an HTML/JS webmapping application which needs to work offline on iPad (and sync back to base when online). Dropbox seemed to provide the only workable solution.
Users should be able to add point features to the webmap and save them to a text file (geojson) in the offline dropbox folder on iPad.
I have created a dropbox app and set the file to be available offline, but am unable to write/overwrite it offline - online I can make a change in any of iPad/PC/Laptop and almost immediately see the updates to the file (valid geojson).
I am using the following code to write the file and, I guess, the offline issue is with the xhr requests and offline use, but I don't know what else to use - any advice would be appreciated. Cheers.
// ** in function called by button click in web map
var data = pt.toGeoJSON();
var convertedData = JSON.stringify(data);
var xhr = new XMLHttpRequest();
xhr.upload.onprogress = function(evt) {
var percentComplete = parseInt(100.0 * evt.loaded / evt.total);
// Upload in progress. Do something here with the percent complete.
};
xhr.onload = function() {
if (xhr.status === 200) {
var fileInfo = JSON.parse(xhr.response);
// Upload succeeded. Do something here with the file info.
}
else {
var errorMessage = xhr.response || 'Unable to upload file';
// Upload failed. Do something here with the error.
}
};
xhr.open('POST', 'https://content.dropboxapi.com/2/files/upload');
xhr.setRequestHeader('Authorization', 'Bearer xyz');
xhr.setRequestHeader('Content-Type', 'application/octet-stream');
xhr.setRequestHeader('Dropbox-API-Arg', JSON.stringify({
path: '/DBXTest.txt',
mode: 'overwrite',
//mode: 'add',
autorename: true,
mute: false
}));
xhr.send(convertedData);