Google App Engine上的Django:无法上传图片 [英] Django on Google App Engine: cannot upload images

查看:187
本文介绍了Google App Engine上的Django:无法上传图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Django应用程序中的模型实现一个ImageField。该应用在Google App Engine上运行。但是,在上传(本地机器,使用GAE SDK 1.7.7)时,我得到一个 [Errno 78]功能未实现

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.

错误起源于 django.core.files.storage.FileSystemStorage._save()

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

我的 MEDIA_ROOT 条目 SETTINGS.PY 包含:

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

我的 MEDIA_URL 条目 SETTINGS.PY 包含:

/media/

媒体目录包含一个名为uploaded的子目录。我检查了这些权限,他们需要读/写访问权限。

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

我的ImageField的字段定义是:

The field definition for my ImageField is:

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



os.path.exists(u'path / to / media / upload')
返回True (这是正确的),所以我不明白为什么Django想要创建目录。

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.

此外,我使用Google Cloud SQL进行存储,并安装了PILLOW进行图像处理也在我的 app.yaml 中添加了PIL作为库。

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...

推荐答案

是的,我想你在这里缺少一些非常基本的东西,无法访问Google App Engine上的文件系统,因此 os.makedirs()将无法正常工作f要上传图像(或一般文件),您必须将其存储在Blobstore或Google Cloud Storage中。在做任何事情之前,我建议您浏览 Blobstore Python API概述您可以在其中看到有关如何上传文件的完整工作示例。

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.

此外,如果您将图像上传为blob,您将能够通过< a href =https://developers.google.com/appengine/docs/python/images/functions#Image_get_serving_url =nofollow> get_serving_url() 通过提供 blob_key 。使用此URL,您可以请求任何大小的特定图像,甚至裁剪服务器端,而不需要额外的努力。

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.

这篇关于Google App Engine上的Django:无法上传图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆