Django Uploadify S3 接收 HTTP 错误

3 投票
2 回答
1087 浏览
提问于 2025-04-16 19:08

我正在使用Django Uplodify S3,但遇到了一些问题,上传文件时进度条显示正在上传,但文件要么无限暂停,要么出现“Http错误”。

我的Python代码几乎和示例代码一模一样。我是在本地机器上用开发服务器运行的。

我一直收到HTTP错误400,亚马逊报告说我的POST请求中有一些额外的字段,这些字段在我的政策中没有指定。

在查看了mouad提供的链接后,我对我的政策做了一些修改,试图包含我应该包含的所有文件,但我不确定我是否正确声明了这些字段,因为Django Uploadify模块的文档有点不清楚。以下是我的代码:

@render
def upload_example(request, object_id):

    options = {"onError":"function (a,b,c,d) {alert('Error: '+d.type+'      Info: '+d.info)} "}
    key_pattern = 'example-%s/${filename}' % object_id
    post_data={
        'key': key_pattern,
        'success_action_status': "201",
        "starts-with": object_id
        }

    #
    # S3 uses conditions to validate the upload data. DUS3 automatically constructs
    # and includes conditions for most of the elements that will be sent to S3, but you 
    # need to pass in conditions for:
    #   - 'key', whose value changes at upload time. Note that the condition's value
    #     must correspond to the key pattern set above.
    #   - any extra elements set at upload time
    #
    # See the DUS3 README for more information on the conditions mapping:
    #   https://github.com/sbc/django-uploadify-s3
    #

    conditions={
        'key': {    'op': 'starts-with',
                    'value': ["$Filename", "$folder", "$key", "$Filedata", "$starts-with", "$Upload"], }
        }

    uploadify_options = uploadify_s3.UploadifyS3(
                            uploadify_options = options,
                            post_data=post_data, 
                            conditions=conditions
                            ).get_options_json()

    return ['s3.html', {"opt": uploadify_options}]

我最担心的部分是'key',它的值在上传时会变化。请注意条件的值。我不确定我应该如何声明key的值。文档真的不太清楚。

然后这是来自亚马逊的错误日志:

7654158c29cb89182a7a8836253c91d61945e514e4a738ee1f502eda245f71e0 joshhunttest [08/Jun/2011:05:24:34 +0000] 137.166.55.199 - 8212E79B67E4469F REST.GET.OBJECT crossdomain.xml "GET /crossdomain.xml HTTP/1.1" 200 - 215 215 199 198 "http://localhost:8000/static/uploadify/uploadify.swf" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_7) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.10 Safari/535.1" -

7654158c29cb89182a7a8836253c91d61945e514e4a738ee1f502eda245f71e0 joshhunttest [08/Jun/2011:05:24:35 +0000] 137.166.55.199 - FDA8CED6EF7C3A19 REST.POST.BUCKET  "POST / HTTP/1.1" 400 MaxPostPreDataLengthExceeded 360 - 1010 - "-" "Adobe Flash Player 10" -

2 个回答

0

我觉得你上传的文件名字应该改成'file',而不是'filedata'。

你可以看看这里的示例代码:http://developer.amazonwebservices.com/connect/entry.jspa?externalID=1092&categoryID=47

0

这可能有点冒险,但你试过把字段名从 file_upload 改成 file 吗?

撰写回答