Question

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 the tutorial under the section Complete sample application:

https://developers.google.com/appengine/docs/python/blobstore/#Python_Complete_sample_application

Most of the time, the uploading process works just fine. Sometimes, however I get the following error message:

 404 Not Found
 The resource could not be found.
 No such upload session: agtkZXZ-b3BlbnZpenIiCxIVX19CbG9iVXBsb2FkU2Vzc2lvbl9fGICAgICA0IcLDA

Has anyone come across this before?

No correct solution

OTHER TIPS

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.

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top