我在heroku上托管了我的代码并使用S3上传文件。一切正常,但上传较大的文件失败。在研究我发现它可能是因为heroku 30s超时。现在我们需要每30秒服务器响应我应该如何实现它。有一个名为Plupload的插件但我不是用户,如果它可以正确地与python集成。有没有其他方法,所以我可以在S3中的模型和文件中存储URL。我在前端使用Dropzone.js来促进ajax。
settings.py
AWS_STORAGE_BUCKET_NAME='xxx'
AWS_ACCESS_KEY_ID='xxxxxxxxxx'
AWS_SECRET_ACCESS_KEY='xxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
AWS_S3_CUSTOM_DOMAIN='xxx.s3-website-us-west-2.amazonaws.com'
STATIC_URL = "http://%s/" % AWS_S3_CUSTOM_DOMAIN
STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
MEDIA_URL = "http://%s/" % AWS_S3_CUSTOM_DOMAIN
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
AWS_S3_SECURE_URLS = False
模板
<script src="https://rawgit.com/enyo/dropzone/master/dist/dropzone.js"></script>
<link rel="stylesheet" href="https://rawgit.com/enyo/dropzone/master/dist/dropzone.css">
<form action="{% url 'harpoons:upload' %}"
class="dropzone"
id="my-awesome-dropzone" method="post">{% csrf_token %}
</form>
views.py
def youmaterial(request):
if request.method == 'POST':
newdoc = Youmaterial(docfile = request.FILES['file'],user=request.user)
newdoc.save()
msg='dee'
# Redirect to the document list after POST
return HttpResponse(json.dumps({'message': msg}))
else:
form1 = DocumentForm()
return render(request,'mat_upload.html',{'form':form1})