目前,默認的Django FileField或上傳方法與我們在使用谷歌Cloud SQL的App Engine的託管應用程序返回以下錯誤:如何將文件上傳到blobstore或通過django-filetransfer?
OSError
[Errno 38] Function not implemented: '/base/data/home/apps/s~app/attachment-1.360717349796013945/media'
這可能是由於文件寫入的應用程序引擎的限制和MKDIR不能正常工作在Django調試模式聲明:
/base/python27_runtime/python27_dist/lib/python2.7/os.py in makedirs
makedirs(head, mode)
except OSError, e:
# be happy if someone already created the path
if e.errno != errno.EEXIST:
raise
if tail == curdir: # xxx/newdir/. exists if xxx/newdir exists
return
mkdir(name, mode) ...
因此,我試圖安裝django-filetransfer和AppEngine上同樣的錯誤仍然存在。
Django的設置:
模式
class OrderItemAttachmentForm(ModelForm):
class Meta:
model = OrderItemAttachment
exclude = ('item',)
def __init__(self, *args, **kwargs):
super(OrderItemAttachmentForm, self).__init__(*args, **kwargs)
查看
def RFO(request):
view_url = reverse('app.views.RFO')
elif 'saveLine' in request.POST:
order_attachment_form = OrderItemAttachmentForm(request.POST,request.FILES)
if order_attachment_form.is_valid():
order_attachment = order_attachment_form.save()
upload_url, upload_data = prepare_upload(request, view_url)
模板
{% load filetransfers %}
<form id="requestItemForm" name="requestItemSubmit" method="post" enctype="multipart/form-data" action="{{ upload_url }}">{% csrf_token %}{% render_upload_data upload_data %}
<div class="lineAttach">
<label for="id_attachment">Upload Attachment</label>
{{order_attachment_form.attachment}}
</div>
<button type="submit" id="saveLine" name="saveLine" class="btn grey doLoad right" value="Save Line Item">Save Line Item</button>
我曾考慮過使用Blobstore python API將文件存儲爲blob或利用Google雲端存儲,但不知道如何將其集成到Django模型中。任何幫助將不勝感激,謝謝!