我有一个 Django 表单,它通过 django-storages 库将文件保存到 s3 并且工作正常。如何生成并返回预签名的 url,以便用户可以在上传后临时访问文件?这是由 django-storages 抽象的还是我必须使用 boto3 api?
我已经花了几个小时浏览 Django-storages 文档,但是目前还不是很清楚如何做到这一点..
表格.py
class DocumentForm(forms.Form):
docfile = forms.FileField(
label='Select a file',
help_text='max. 42 megabytes'
)
name = models.CharField(max_length=20)
uploaded_at = models.DateTimeField(auto_now_add=True)
视图.py
def upload_file(request):
if request.method == 'POST:
form = DocumentForm(request.POST)
if form.is_valid():
form.save()
url = #generate pre-signed url of uploaded file here
return render(request, 'upload_response.html', url)