I can't upload media files to Amazon S3 using django-storages
and boto
, and following this tutorial. I've also checked these questions:
boto.exception.S3ResponseError: S3ResponseError: 403 Forbidden
Getting boto.exception.S3ResponseError: S3ResponseError: 403 Forbidden when uploading file
But I am not able to use them successfully. I always get the error: S3ResponseError: 403 Forbidden
My bucket policy is:
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "PublicReadForGetBucketObjects",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::<bucket name>/*"
},
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"AWS": "<arn info>"
},
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::<bucket name>",
"arn:aws:s3:::<bucket name>/*"
]
}
]
}
models.py
class Usuario(models.Model):
user = models.OneToOneField(User, primary_key=True)
titulo = models.CharField(max_length=100, null=True, blank=True)
avatar = models.ImageField(upload_to='avatars', null=True, blank=True)
views.py
@require_POST
@login_required(login_url='/acceso/')
def configuracion_usuario_guardar(request):
u = User.objects.get(pk=request.user.id)
c = Usuario.objects.get(pk=request.user.id)
nombre = request.POST.get('nombre', '')
apellido = request.POST.get('apellido', '')
cargo = request.POST.get('cargo', '')
email = request.POST.get('email', '')
avatar = request.FILES.get('avatar', '')
u.first_name = nombre
u.last_name = apellido
u.email = email
u.save()
c.titulo = cargo
c.avatar = avatar
c.save()
return HttpResponseRedirect('/perfil/')
Any ideas?