Ошибка отказа в разрешении на django-s3direct
При загрузке файла на S3
в консоли появляется ошибка следующего содержания
[WARNING][220126 010447] Forbidden: /s3direct/get_aws_v4_signature/
[26/Jan/2022 01:04:47] "POST /s3direct/get_aws_v4_signature/ HTTP/1.1" 403 31
и Permission denied
всплывающее окно отображается в браузере.
Я снова и снова проверял учетные данные и имя ведра, но опечатки нет.
и я могу загрузить файл с этой учетной записью из aws-cli
Однако этот код django показывает ошибку разрешения.
Где я должен проверить?
в settins.py
настройка среды AWS.
AWS_ACCESS_KEY_ID = '**********'
AWS_SECRET_ACCESS_KEY = '*******************'
AWS_STORAGE_BUCKET_NAME = 'vr-dev-bot-resource-bucket'
AWS_S3_REGION_NAME = 'ap-northeast-1'
AWS_S3_ENDPOINT_URL = 'https://s3.ap-northeast-1.amazonaws.com'
S3DIRECT_DESTINATIONS = {
'example_destination': {
# "key" [required] The location to upload file
# 1. String: folder path to upload to
# 2. Function: generate folder path + filename using a function
'key': 'uploads/images',
# "auth" [optional] Limit to specfic Django users
# Function: ACL function
'auth': lambda u: u.is_staff,
# "allowed" [optional] Limit to specific mime types
# List: list of mime types
'allowed': ['image/jpeg', 'image/png', 'video/mp4'],
# "bucket" [optional] Bucket if different from AWS_STORAGE_BUCKET_NAME
# String: bucket name
'bucket': 'custom-bucket',
# "endpoint" [optional] Endpoint if different from AWS_S3_ENDPOINT_URL
# String: endpoint URL
'endpoint': 'custom-endpoint',
# "region" [optional] Region if different from AWS_S3_REGION_NAME
# String: region name
'region': 'custom-region', # Default is 'AWS_S3_REGION_NAME'
# "acl" [optional] Custom ACL for object, default is 'public-read'
# String: ACL
'acl': 'private',
# "cache_control" [optional] Custom cache control header
# String: header
'cache_control': 'max-age=2592000',
# "content_disposition" [optional] Custom content disposition header
# String: header
'content_disposition': lambda x: 'attachment; filename="{}"'.format(x),
# "content_length_range" [optional] Limit file size
# Tuple: (from, to) in bytes
'content_length_range': (5000, 20000000),
# "server_side_encryption" [optional] Use serverside encryption
# String: encrytion standard
'server_side_encryption': 'AES256',
# "allow_existence_optimization" [optional] Checks to see if file already exists,
# returns the URL to the object if so (no upload)
# Boolean: True, False
'allow_existence_optimization': False,
},
'example_destination_two': {
'key': lambda filename, args: args + '/' + filename,
'key_args': 'uploads/images',
}
}
в views.py
, делает вид.
from django.shortcuts import render
# Create your views here.
from django.views.generic import FormView
from .forms import S3DirectUploadForm
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world.")
class MyView(FormView):
template_name = 'form.html'
form_class = S3DirectUploadForm
в forms.py
from django import forms
from s3direct.widgets import S3DirectWidget
class S3DirectUploadForm(forms.Form):
images = forms.URLField(widget=S3DirectWidget(dest='example_destination'))
в form.html
<html>
<head>
<meta charset="utf-8">
<title>s3direct</title>
{{ form.media }}
</head>
<body>
<form action="" method="post">{% csrf_token %}
{{ form.as_p }}
</form>
</body>
</html>
S3 Cross-Origin Resource Sharing setting.
[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"GET",
"HEAD",
"PUT",
"DELETE"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": []
}
]