简体   繁体   English

Google App Engine上的Django:无法上传图片

[英]Django on Google App Engine: cannot upload images

I'm trying to implement an ImageField for a model in my Django app. 我正在尝试在Django应用中为模型实现ImageField。 The app runs on Google App Engine. 该应用程序在Google App Engine上运行。 However upon upload (local machine, using GAE SDK 1.7.7) I get an [Errno 78] Function not implemented . 但是,在上传后(使用GAE SDK 1.7.7在本地计算机上),我得到了一个[Errno 78] Function not implemented

The error originates from a call to os.makedirs() in django.core.files.storage.FileSystemStorage._save() ; 该错误源自对django.core.files.storage.FileSystemStorage._save() os.makedirs()的调用; the argument for the call to makedirs is: 调用makedirs的参数为:

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

My MEDIA_ROOT entry in SETTINGS.PY contains: 我在SETTINGS.PY中的MEDIA_ROOT条目包含:

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

My MEDIA_URL entry in SETTINGS.PY contains: 我在SETTINGS.PY中的MEDIA_URL条目包含:

/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: 我的ImageField的字段定义是:

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

For some reason Django wants to create the directory which already exists. 由于某种原因,Django想要创建已经存在的目录。 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. 使用Django控制台os.path.exists(u'path/to/media/upload')返回True(正确),所以我不明白Django为什么要创建目录。

Additionally, I use Google Cloud SQL for storage and installed PILLOW for image handling. 此外,我使用Google Cloud SQL进行存储,并使用PILLOW进行图像处理。 I also added PIL as library in my app.yaml . 我还在我的app.yaml中将PIL添加为库。

I'm probably missing something elementary, but am clueless at the moment to what's causing this... 我可能缺少一些基本知识,但目前对导致此问题的原因一无所知...

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. 您无权访问Google App Engine上的文件系统,因此os.makedirs()无法正常工作。 If you want to upload images (or files in general) you have to store them in Blobstore or in Google Cloud Storage. 如果要上传图像(或一般文件),则必须将其存储在Blobstore或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. 在执行其他任何操作之前,我建议您仔细阅读Blobstore Python API概述 ,在这里您可以看到有关如何上传文件的完整示例。

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 . 此外,如果您将图像上传为Blob,则可以通过提供blob_key来通过get_serving_url()获取图像服务URL。 With this URL you can request any size for a particular image or even crop it server side without any extra effort. 使用此URL,您可以为特定图像请求任何大小,甚至可以在服务器端进行裁剪。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM