This is the first time I've contacted AWS S3 to store media. The application is hosted in Heroku, for static files this was not a problem, so I do not want to change static files, but I want application users to upload files and images that I want to save to S3. I have already spent 2-3 days so far and have not found the right solution, since I get an exception of 400 for no good reason. Here is the documentation I was talking about:
http://tech.marksblogg.com/file-uploads-amazon-s3-django.html
So, my settings are now:
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
AWS_S3_ACCESS_KEY_ID='dummyid'
AWS_S3_SECRET_ACCESS_KEY='dummykey'
AWS_STORAGE_BUCKET_NAME='dummyname'
AWS_QUERYSTRING_AUTH = False
AWS_HEADERS = {'Cache-Control': 'max-age=86400', }
MEDIAFILES_LOCATION = 'media'
MEDIA_URL = 'http://%s.s3.amazonaws.com/media/' % AWS_STORAGE_BUCKET_NAME
My model:
class DummyDocuments(models.Model):
document = models.FileField(upload_to='documents')
My form:
class DummyUploadForm(forms.Form):
documents = forms.FileField(widget=forms.ClearableFileInput(attrs={'multiple': True}))
And here is the view in which I use it:
def upload(request):
if request.method == 'POST':
form = DummyUploadForm(request.POST, request.FILES)
if form.is_valid():
files = request.FILES.getlist('documents')
for file in files:
instance = DummyDocuments(document=file)
instance.save()
return redirect('activation_upload')
else:
form = DummyUploadForm()
documents = DummyDocuments.objects.all()
return render(request, 'activation/dummyupload.html', {'form': form, 'documents': documents})
Here is my CORS configuration on AWS:
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
Here is the exception I get:

May I find out what exactly is wrong?
django , . , .
:
AWS_S3_HOST = 's3.ca-central-1.amazonaws.com'
~/.boto config :
[Credentials]
aws_access_key_id=yourid
aws_secret_access_key=yourkey
[s3]
host=s3.ca-central-1.amazonaws.com