使用django-s3upload上传到S3时保留文件名

时间:2013-09-13 00:15:04

标签: jquery python django file-upload amazon-s3

我正在使用django-s3upload将文件上传到我的s3存储桶。我已经把它运行得很好但是由于某些原因我不明白,将所有上传的文件重命名为带有.bin扩展名的随机十六进制字符串。我可以看到代码发生在哪里:

def get_upload_params(request):
    def make_policy():
        policy_object = {
            "expiration": (datetime.now() + timedelta(hours=24)).strftime('%Y-%m-%dT%H:%M:%S.000Z'),
            "conditions": [
                { "bucket": settings.AWS_S3_BUCKET_NAME },
                { "acl": "public-read" },
                ["starts-with", "$key", "uploads/"],
                { "success_action_status": "201" }
            ]
        }
        return b64encode(dumps(policy_object).replace('\n', '').replace('\r', ''))

    def sign_policy(policy):
        return b64encode(hmac.new(settings.AWS_SECRET_ACCESS_KEY, policy, sha).digest())

    policy = make_policy()
    return HttpResponse(dumps({
        "policy": policy,
        "signature": sign_policy(policy),
        "key": "uploads/" + uuid4().hex + ".bin",
        "success_action_redirect": "/"
    }), content_type="application/json")

我无法弄清楚如何保持文件名完好无损。执行所有上传工作客户端的jQuery文件是here

0 个答案:

没有答案