在Android 4.3上使用Phonegap中的FileTransfer将文件上传到S3时的代码3 [英] Code 3 when uploading file to S3 using FileTransfer in Phonegap on Android 4.3

查看:85
本文介绍了在Android 4.3上使用Phonegap中的FileTransfer将文件上传到S3时的代码3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用FileTransfer和以下版本将我的Cordova/Phonegap 3.2应用程序的图像文件上传到Amazon S3 时,出现"代码3 "(连接错误)错误. Android 4.3 版本平台.

I am getting "Code 3" (connection error) error when trying to upload an image file from my Cordova / Phonegap 3.2 app to Amazon S3 using FileTransfer and in Android 4.3 version platform.

 options.fileKey = "file";
    options.fileName = filename_for_s3;
    options.mimeType = "image/jpeg";
    options.chunkedMode = false;
    options.headers = {
        Connection: "close"
    }

ft.upload(imageURI, encodeURI("https://" + data.Bucket + ".s3.amazonaws.com/"), success, fail, options);

该代码可在iOS7和更早的Android版本(在Android 3.2和2.3上测试)上工作,但是我的问题是4.3版本.我认为问题不在于代码本身,因为它与其他版本一起使用,但可能是Phonegap库本身.

The code works on iOS7 and older Android versions (tested on Android 3.2 and 2.3), but my problem is with version 4.3. I assume that the problem is not with the code itself, as it works with other version, but might be the Phonegap library itself.

可能有解决方法,但我不熟悉.我尝试过许多关于类似问题的选项,例如将chunkedMode更改为false,而不对URI进行编码,而是添加"Connection:'close'"标头,但它仍然无法正常工作.其他人则认为这可能是导致该问题的Google Analytics(分析)插件的问题,因此我将其删除,但仍然遇到相同的错误.我还尝试了这个问题的答案,但没有成功.

There might be a workaround but I am not familiar with it. I tried many options posted on what it seems like a similar problem, like changing the chunkedMode to false, without encoding the URI, adding "Connection: 'close'" header but it still doesn't work. Others suggested that this might be an issue with the google analytics plugin that causes it, so I removed it and I still get the same error. I also tried the answers in this question without success.

我还想补充一点,我正在服务器上生成签名和策略.

I also want to add that I am generating a signature and policy on the server.

  options.params = {

     "key": "uploads/" + filename_for_s3,
     "AWSAccessKeyId": data.AWSAccessKey,
     'success_action_status': '201',
     "acl": "private",
     "policy": data.Policy,
     "signature": data.Signature

                };

Cors权限也可以根据需要设置:

Cors permissions are also set as needed:

 <?xml version="1.0" encoding="UTF-8"?>
 <CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
    <AllowedOrigin>*</AllowedOrigin>
    <AllowedMethod>GET</AllowedMethod>
    <AllowedMethod>POST</AllowedMethod>
    <AllowedMethod>PUT</AllowedMethod>
    <AllowedMethod>HEAD</AllowedMethod>
    <MaxAgeSeconds>3000</MaxAgeSeconds>
    <ExposeHeader>ETag</ExposeHeader>
    <ExposeHeader>x-amz-meta-custom-header</ExposeHeader>
    <AllowedHeader>*</AllowedHeader>
</CORSRule>

更新:我还检查了Amazon S3日志,但是没有任何与上载相关的行.

Update: I also checked the Amazon S3 logs, but there isn't any line related to an upload.

我花了几天时间试图解决这个问题,但没有成功.希望您能帮助我解决此问题.谢谢.

I've spent a few days trying to figure it out without any success. I hope that you can help me solve this issue. Thanks.

这似乎是Cordova 3.2(

It seems like this is a bug in Cordova 3.2 (see my post here). I was suggested to use the latest FileTransfer library, and also updated the File library, however I get an error when compiling.

我需要帮助来解决此问题.

I need help to solve this issue.

更新:将FileTransfer,File和Capture插件更新到最新版本并不能解决问题,实际上,现在它也在iOS7上引发了代码3-以前从未发生过./p>

Update: updating the FileTransfer, File and Capture plugins to the newest version didn't solve the problem, in fact, now it throws Code 3 on iOS7 too - didn't happen before.

推荐答案

您是否尝试过ft.upload(imageURI,"https://" + data.Bucket + ".s3.amazonaws.com/", success, fail, options);?看起来您正在对网址的://部分进行URL编码.

Have you tried ft.upload(imageURI,"https://" + data.Bucket + ".s3.amazonaws.com/", success, fail, options); ? Looks like you are URL encoding the :// parts of the url.

这篇关于在Android 4.3上使用Phonegap中的FileTransfer将文件上传到S3时的代码3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆