I am using GAE with Python 2.7 to make a website which can upload files with ascii data to the blobstore. The code I am using for this is pretty much the same as given in th
The URL that you are getting with create_upload_url()
has a certain timeout (which is 10 minutes) so if you are retrieving this URL when the webpage is loaded and it takes a while to upload the actual data it will eventually expire and return 404. I would suggest you to get the upload URL just before uploading the data.
There are a few bugs in the demo. The proximate one is that it wants you to be logged in. Log in via http://localhost:8080/_ah/login (and press the Login button). You'll need to manually navigate back to http://localhost:8080/ The demo should work after that.
We solved this 10 minute timeout problem by implementing a small amount of Javascript which every 9 minutes sends an ajax request to a URL which sends back a new blob upload URL and swaps out the form.
The /ajax/blob
URL takes a success url, and then calls create_upload_url()
and returns it as an ajax data object.
Here's the Javascript we wrote:
if ($('#blobUploadForm').length > 0) {
setTimeout(_getNewBlobstoreUrl, 9 * 1000 * 60 * 60); // 9 minutes
} //do nothing if there is no uploadUrl id
function _getNewBlobstoreUrl() {
var successUrl = $('#uploadUrl').attr('value');
if (typeof successUrl == 'undefined') {
return;
}
var url = "/ajax/blob?url=" + successUrl;
$.ajax({
url: url,
dataType: "json",
cache: false,
async: true,
success: _getNewBlobstoreUrlSuccess,
error: _getNewBlobstoreUrlError
})
function _getNewBlobstoreUrlSuccess(data) {
if (data.url) {
//change the action to a new action
$('#blobUploadForm').attr('action', data.url)
}
}
function _getNewBlobstoreUrlError(err) {
// do something
}
Don't forget at the end to setup the timeout again too (or use setInterval?), in case the user takes a really long time to fill in the form.