0

Quick notes - I'm trying to upload random size files to save at datastore using GAE.

Here is basic code:

  • HTML Code

    <iframe name="upload_iframe" src="" style="display:none;"></iframe>
    <form method="post" enctype="multipart/form-data" action="/">
      <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
      <input name="data_file" size="30000" type="file" /> <input type="submit" name="submit" value="Upload" />
    </form>
    
  • Python / Django Code

     def upload_files(request):
        if request.method == 'POST':
           logging.info(request.FILES)
           logging.info(request.FILES['data_file'])
    
        return HttpResponse('File Uploaded Successfully..')
    

Test scenario :

  • If i try to upload ~1 Mb file, its working fine.. returns File Uploaded Successfully

  • if trying to upload ~2 Mb or more then it raises MultiValueDictKeyError: "Key 'data_file' not found in <MultiValueDict: {}>" :- not able to picked up where am i doing wrong here or using wrong approch..

I referred this SO Question too..but its not working for me.

Please suggest you thought on above..

Community
  • 1
  • 1
Niks Jain
  • 1,617
  • 5
  • 27
  • 53
  • Some tips: Use `{% csrf_protect %}`; get rid of the hidden `MAX_FILE_SIZE` because it is not doing anything useful; and there is no `size` attribute for file input tag. – Burhan Khalid Aug 06 '13 at 08:02
  • @BurhanKhalid: Thanks for your reply.. Could you please elaborate this tips with some example or with use of `{% csrf_protect %}` ? – Niks Jain Aug 06 '13 at 08:43
  • See the [documentation on CSRF](https://docs.djangoproject.com/en/1.5/ref/contrib/csrf/) – Burhan Khalid Aug 06 '13 at 08:55

1 Answers1

0

Django loads small file uploads into memory, while saving large uploads temporary to disk. GAE doesn't allow access to the file-system, so you have to incorporate GAE's blobstore as storage engine. Also refer to this question on SO.

Community
  • 1
  • 1
Bouke
  • 11,768
  • 7
  • 68
  • 102