目前,我们使用 Google Cloud SQL 在应用引擎上托管的应用程序的默认 Django FileField 上传方法返回以下错误:
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 Cloud Storage,但不知道如何将其集成到 Django 模型中。任何帮助将不胜感激,谢谢!