S3ResponseError:403禁止

时间:2015-08-24 19:16:54

标签: django amazon-web-services amazon-s3 boto

我无法使用django-storagesboto以及this tutorial将媒体文件上传到Amazon S3。我也检查了这些问题:

boto.exception.S3ResponseError: S3ResponseError: 403 Forbidden

Getting boto.exception.S3ResponseError: S3ResponseError: 403 Forbidden when uploading file

但我无法成功使用它们。我总是收到错误:S3ResponseError: 403 Forbidden

我的存储桶政策是:

{
"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/')

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

对我来说,问题是在我使用的模板中:

{% load static %}

当我换到

{% load static from staticfiles %} 

我全部工作了! 希望我帮助别人!