gpt4 book ai didi

python - 无法将文件上传到 App Engine "list index out of range"

转载 作者:行者123 更新时间:2023-11-28 23:04:50 25 4
gpt4 key购买 nike

我正在尝试将图片从 Phonegap 应用程序上传到我的 Python App Engine 项目。手机应用程序尝试上传文件,但 App 引擎返回“列表索引超出范围”错误。

我在 App Engine 端有以下代码来处理文件,

class UploadHandler(blobstore_handlers.BlobstoreUploadHandler):
def post(self):
upload_files = self.get_uploads('file')
blob_info = upload_files[0]
self.redirect('/serve/%s' % blob_info.key())

PhoneGap端发送文件的代码如下,

    function uploadImage() {
var smallImage = document.getElementById('cameraImage');
if (smallImage.src && smallImage.src !== "") {
var f = new FileTransfer();
f.upload(smallImage.src, "http://testtest.appspot.com/upload",
// success callback
function(result) {
document.getElementById('uploadProgress').innerHTML =
result.bytesSent + ' bytes sent';
alert(result.responseCode + ": " + result.response);
},
// error callback
function(error) {
alert('error uploading file: ' + error.code);
},
// options
{ fileName: 'myImage.jpg',
params: { 'username':'jtyberg' }
});
}
}

错误如下,

"POST /upload HTTP/1.1" 500 487 - "BlackBerry9550/5.0.0.469 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/-1" "testtest.appspot.com" ms=416 cpu_ms=93 api_cpu_ms=0 cpm_usd=0.014221 loading_request=1 instance=00c61b117ca6c4ea405471eea592a8f79ac6
E 2011-08-06 11:49:17.309
list index out of range
Traceback (most recent call last):
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/__init__.py", line 702, in __call__
handler.post(*groups)
File "/base/data/home/apps/s~testtest/1.352363227571120815/main.py", line 62, in post
blob_info = upload_files[0]
IndexError: list index out of range

当我尝试通过 Web 表单上传文件时,效果很好。

最佳答案

您需要通过 blobstore.create_upload_url('/upload') 生成上传 url。现在,您正在直接对您的上传处理程序 URL 进行多部分 POST。中间 url 很关键,因为它会生成一个 Blobstore key 并将其添加到 MIME header ,然后再将其传递给处理程序。

关于python - 无法将文件上传到 App Engine "list index out of range",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6988557/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com