python - 使用 Django Uploadify S3 接收 HTTP 错误

标签 python django amazon-s3

我正在使用 Django Uplodify S3我在让它工作时遇到了问题。文件开始上传(显示进度),然后它们要么无限期暂停,要么导致“Http 错误”。

我的 python 代码与给出的示例代码几乎相同。我正在使用开发服务器在我的本地机器上运行它。

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

查看提供的链接 mouad 后,我对我的策略进行了一些更改以尝试包含我应该包含的所有文件,但我不确定我是否已正确声明它们,因为 Django Uploadfiy 模块的文档是有点不清楚。这是我拥有的:

@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" -

最佳答案

这可能不太成功,但您是否尝试过将字段从 file_upload 重命名为 file

关于python - 使用 Django Uploadify S3 接收 HTTP 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6274484/

相关文章:

ruby-on-rails - 如何将远程文件分配给 Carrierwave?

amazon-web-services - 上传文件到 AWS S3 占用大量 CPU

python - 根据特定列中的条件应用公式

python - xlsxwriter下拉列表Excel错误

python - 如何在 turtle 图形中显示两条重叠的线

django - 查看 Django 查询集删除的 SQL 查询

python - 防止在 Django 中自动转义自定义模板标签

c++ - 带 swig 的 auto_ptr

django - 如何在 Django Crispy Forms 中包含 HTML header 标签?

ruby-on-rails - Rails 中未显示视频 HTML 标记