0

I am new to Google App Engine. I have deploy the pure django application in google app engine. It is working fine. But I wrote the django file upload functionality as shown below,

def forhandler(list, project_id, task_id, request):
    for i in list:
        filename = i
        extension = filename.content_type
        print i
        newdoc = FileUpload(project_id=project_id, task_id=task_id, file=filename, filetype=extension)
        newdoc.save()

When I run the ./manage.py runserver. The above functionality working correctly and uploading files correctly. When I use google app engine means dev_appserver.py my_project. It is perfect but when I upload the file using above functionality It gives an error as shown below,

Exception Value: [Errno 30] Read-only file system: u'/home/nyros/Desktop/projectstat/projectstat/media/documents/2013/05/24/1354676051_chasm_fishing_w1.jpeg'

How do I upload the file using django with google app Engine ? Please solve my problem.Thanks......

dhana
  • 6,487
  • 4
  • 40
  • 63
  • possible duplicate of http://stackoverflow.com/questions/2693081/does-google-app-engine-allow-creation-of-files-and-folders-on-the-server – Samuele Mattiuzzo May 24 '13 at 09:29

2 Answers2

5

The problem here is that App Engine uses a read-only filesystem, and the default Django file upload mechanism wants to store files on disk. (Regardless of whether you're using App Engine or not, storing images in an ordinary database is a bad idea.)

Instead, you should use AppEngine's Blobstore API to save the image. This is special storage App Engine provides for storing large data uploaded by users.

The good news is there's a plugin that takes care of all of this for you: http://www.allbuttonspressed.com/projects/django-filetransfers

Just follow the instructions there and you should be in business.

(Note: I've only tried this with django-nonrel. I've never tried with with vanilla Django.)

Trevor Johns
  • 15,682
  • 3
  • 55
  • 54
1

The best way to upload files in google app engine with python is using the blobstorehandler.

class Upload(blobstore_handlers.BlobstoreUploadHandler):

    for upload in self.get_uploads():
        try:
            img = Image()
            img.primary_image = upload.key()
            img.put()
        except:
            pass
Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424