如何使用Django和Google App Engine Blobstore API上传文件 [英] How to upload a file using Django and Google App Engine Blobstore API

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

问题描述

我有一个我正在开发的应用程序:




  • Django 1.5

  • Google App Engine

  • Google Cloud SQL

  • Python 2.7.5



使用Cloud SQL我正在使用纯Django,而不是no-rel版本,充分利用了Django ORM。



在应用程式的管理员部分,我想使用表格上传使用GAE Blobstore API的csv档案。



我想要实现的是将文件上传到Blobstore和Blob Key,将引用此上传的文件保存在我的模型中。



去做这个吗



感谢您的帮助。

解决方案

将文件作为Django表单的一部分上传,您可以按照BlobStore指令手动处理uplaod,然后获取BlobKey,并将其保存为Django模型中的字符串。这可能是最直接的方式。



https://developers.google.com/appengine/docs/python/blobstore/



另一种选择是将存储组件djangoappengine(专为Django-nonrel设计),并适应它与普通的Django一起使用。我不认为这有什么理由不适用(在你做了一些努力去适应之后)



https://github.com/django-nonrel/djangoappengine/blob/master/djangoappengine/storage.py


I have an app I am developing using:

  • Django 1.5
  • Google App Engine
  • Google Cloud SQL
  • Python 2.7.5

As using Cloud SQL I am using the pure Django not the no-rel version making full use of the Django ORM.

In the admin part of the app I want to have a form to upload a csv file using GAE Blobstore API.

What I want to achieve is the uploading of the file to the Blobstore and the Blob Key referencing this uploaded file to be saved in my model.

How would I go about doing this?

Thanks for your help.

解决方案

If you're not uploading the file as part of a Django form, you can manually handle the uplaod as per BlobStore instructions, then fetch the BlobKey, and save it as a string in your Django model. That's probably the most straighforward way to go.

https://developers.google.com/appengine/docs/python/blobstore/

Another option is to take the storage component in djangoappengine (designed for Django-nonrel), and adapt it for use with normal Django. I don't think there's any reason why this shouldn't work (after you put some effort into adapting it)

https://github.com/django-nonrel/djangoappengine/blob/master/djangoappengine/storage.py

这篇关于如何使用Django和Google App Engine Blobstore API上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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