google app engine; upload to blobstore gives 404 error

前端 未结 3 1151
终归单人心
终归单人心 2021-01-15 22:39

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

相关标签:
3条回答
  • 2021-01-15 23:15

    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.

    0 讨论(0)
  • 2021-01-15 23:17

    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.

    0 讨论(0)
  • 2021-01-15 23:26

    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.

    0 讨论(0)
提交回复
热议问题