3

I'm trying to implement an ImageField for a model in my Django app. The app runs on Google App Engine. However upon upload (local machine, using GAE SDK 1.7.7) I get an [Errno 78] Function not implemented.

The error originates from a call to os.makedirs() in django.core.files.storage.FileSystemStorage._save(); the argument for the call to makedirs is:

u'/Users/.../PycharmProjects/myproject/media/uploaded

My MEDIA_ROOT entry in SETTINGS.PY contains:

/Users/.../PycharmProjects/myproject/media/

My MEDIA_URL entry in SETTINGS.PY contains:

/media/

The media directory contains a sub-directory named 'uploaded'. I checked the privileges and they have required read/write access.

The field definition for my ImageField is:

image = models.ImageField(upload_to = "uploaded/"

For some reason Django wants to create the directory which already exists. Using the Django console os.path.exists(u'path/to/media/upload') returns True (which is correct) so I do not understand why Django wants to create the directory.

Additionally, I use Google Cloud SQL for storage and installed PILLOW for image handling. I also added PIL as library in my app.yaml.

I'm probably missing something elementary, but am clueless at the moment to what's causing this...

Roger
  • 4,737
  • 4
  • 43
  • 68
  • You could also take a look in a bit more advanced example for uploading files/images with GAE from here: http://upload.gae-init.appspot.com/resource/upload/ – Lipis Apr 15 '13 at 12:51
  • Thanks. Very helpful. I was thrown off a bit by that piece of code trying to create a directory. But I should have read the docs first... – Roger Apr 15 '13 at 13:37

1 Answers1

5

Yes, I think you are missing something very basic here. You don't have access to the file system on Google App Engine so the os.makedirs() won't work. If you want to upload images (or files in general) you have to store them in Blobstore or in Google Cloud Storage. Before doing anything else I would suggest you to go through the Blobstore Python API Overview where you can see the fully working example on how to upload files.

Further if you have images uploaded as blobs you will be able to get the image serving URL through get_serving_url() by providing the blob_key. With this URL you can request any size for a particular image or even crop it server side without any extra effort.

Lipis
  • 21,388
  • 20
  • 94
  • 121