我设置了一个测试脚本,几乎与此处的示例完全相同: https ://github.com/GoodCloud/django-ajax-uploader
似乎开始上传文件(javascript 更新文件的名称和大小),但视图给我一个 500 错误与此消息。我找不到任何关于如何修复它的信息。
S3ResponseError: S3ResponseError: 400 Bad Request
<Error><Code>MalformedXML</Code><Message>The XML you provided was not well-formed or did not validate against our published schema</Message><RequestId>26E6EF8296A0E585</RequestId><HostId>F4QUOsVT4LxC+6OUP2lE1/9uPC77keOejyWs57GpS5kjvHXpun3U+81ntL8ZTgDa</HostId></Error>
我能够使用 boto 使用此处的命令在 shell 中上传文件: Upload 0 byte file to Amazon S3
风景:
from ajaxuploader.views import AjaxFileUploader
from ajaxuploader.backends.s3 import S3UploadBackend
import_uploader = AjaxFileUploader(backend=S3UploadBackend)
javascript:
var uploader = new qq.FileUploader({
action: "/ajax/profile-upload/",
element: $('#file-uploader')[0],
multiple: true,
onComplete: function(id, fileName, responseJSON) {
if(responseJSON.success) {
alert("success!");
} else {
alert("upload failed!");
}
},
onAllComplete: function(uploads) {
// uploads is an array of maps
// the maps look like this: {file: FileObject, response: JSONServerResponse}
alert("All complete!");
},
params: {
'csrf_token': $('[name=csrfmiddlewaretoken]').val(),
'csrf_name': 'csrfmiddlewaretoken',
'csrf_xname': 'X-CSRFToken',
},
});
模板:
<div id="file-uploader">
<noscript>
<p>Please enable JavaScript to use file uploader.</p>
</noscript>
</div>
我的 settings.py 文件中有 s3 访问变量(它们在 ajaxuploader/backends/s3.py 文件中调用):
AWS_ACCESS_KEY_ID = myAccessKey
AWS_SECRET_ACCESS_KEY = mySecretKey
AWS_BUCKET_NAME = bucketName