如何上传文件在django谷歌应用程序引擎? [英] How to upload file in django google app engine?

查看:176
本文介绍了如何上传文件在django谷歌应用程序引擎?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Google App Engine的新手。我已经在谷歌应用程序引擎中部署了纯django应用程序。工作正常但是我写了django文件上传功能,如下所示,

  def forhandler(list,project_id,task_id,request):
列表中的i:
filename = i
extension = filename.content_type
print i
newdoc = FileUpload(project_id = project_id,task_id = task_id,file = filename,filetype = extension)
newdoc.save()

当我运行./manage.py runserver命令。以上功能正常工作并正确上传文件。当我使用google app引擎意味着dev_appserver.py my_project。这是完美的,但是当我使用上述功能上传文件时,会出现如下所示的错误,

 异常值:[Errno 30 ]只读文件系统:u'/ home / nyros / Desktop / projectstat / projectstat / media / documents / 2013/05/24 / 1354676051_chasm_fishing_w1.jpeg'

如何使用django和google app Engine上传文件?请解决我的问题。谢谢......

解决方案

这个问题在于App Engine使用只读文件系统,并且默认的Django文件上传机制希望将文件存储在磁盘上。 (无论是否使用App Engine,将图像存储在普通数据库中是一个坏主意。)



相反,您应该使用AppEngine的Blobstore API来保存图片。这是App Engine提供的用于存储用户上传的大型数据的特殊存储。



好消息是有一个插件可以为您照顾所有这些: http://www.allbuttonspressed.com/projects/django-filetransfers



(注意:我只用django-nonrel尝试过,我从来没有尝试过与香草Django。)


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

解决方案

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

这篇关于如何上传文件在django谷歌应用程序引擎?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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