現在、Google Cloud SQL を使用してアプリ エンジンでホストしているアプリケーションでのデフォルトの Django FileField アップロード メソッドは、次のエラーを返します。
OSError
[Errno 38] Function not implemented: '/base/data/home/apps/s~app/attachment-1.360717349796013945/media'
これはおそらく、アプリ エンジンでファイルの書き込みが制限されており、Django デバッグ モードで mkdir が機能しないことが原因です。
/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 で同じエラーが発生します。
ジャンゴのセットアップ:
モデル
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 モデルに統合する方法がわかりません。どんな助けでも大歓迎です、ありがとう!