Phonegap 的 FileTransfer.upload() 在 Android 上抛出错误代码 3

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11783985/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 08:51:19  来源:igfitidea点击:

Phonegap's FileTransfer.upload() throwing error code 3 on Android

androidcordovaupload

提问by user1572156

I am working on uploading a picture to a server. I am able to successfully upload an image using iOS but when i try on android I get the error code 3. Currently using phonegap cordova 1.8.1.

我正在将图片上传到服务器。我能够使用 iOS 成功上传图像,但是当我尝试使用 android 时,我收到错误代码 3。目前使用的是 phonegap cordova 1.8.1。

I already tried adding true to the parameters

我已经尝试在参数中添加 true

upload(filePath, server, successCallback, errorCallback, options, **true**);

and adding this

并添加这个

options.chunkedMode = false;

My AndroidManifest file contains:

我的 AndroidManifest 文件包含:

<uses-permission android:name="android.permission.INTERNET" />

My cordova.xml file contains:

我的cordova.xml 文件包含:

<access origin="*"/>

Am I missing something?

我错过了什么吗?

Thanks

谢谢

回答by Marcio Ota

The issue probably is not in Phonegap. if the server is a Windows based server, try using another server. Also, don′t forget to add these lines:

问题可能不在Phonegap。如果服务器是基于 Windows 的服务器,请尝试使用另一台服务器。另外,不要忘记添加这些行:

var options = new FileUploadOptions();
options.chunkedMode = false;
options.headers = {
      Connection: "close"
   };

回答by Tsybulsky Serg

add code:

添加代码:

var op;
op = new FileUploadOptions();

op.headers = {
    Connection: "close"
};

After adding this - code started to work well with no errors. A bit more detailed description: http://grandiz.com/phonegap-development/phonegap-file-transfer-error-code-3-solvedHope that helps!

添加此代码后 - 代码开始运行良好,没有错误。更详细的描述:http: //grandiz.com/phonegap-development/phonegap-file-transfer-error-code-3-solved希望有帮助!

回答by Suyash Sumaroo

These are steps I used to overcome this problem:

这些是我用来克服这个问题的步骤:

Added the following options:

添加了以下选项:

options.chunkedMode = false;
options.headers = {
      Connection: "close"
   };

But more important was the fact that I was using Genymotion as the emulator for testing. Uploading the image to localhost was not working because the emulator was running in a VM and localhost meant the VM's localhost and not the localhost of your web server.

但更重要的是我使用 Genymotion 作为模拟器进行测试。将图像上传到 localhost 不起作用,因为模拟器在 VM 中运行,而 localhost 表示 VM 的 localhost 而不是 Web 服务器的 localhost。

So instead of uploading to 'localhost', you should upload to:

因此,与其上传到“localhost”,不如上传到:

http://10.0.2.2 

and add the following line to your config.xml:

并将以下行添加到您的 config.xml 中:

<access origin="10.0.2.2" subdomains="true"/>

I tested it and its working like a charm. Took me 3 days to get this working though.

我测试了它,它的工作原理就像一个魅力。不过,我花了 3 天的时间才完成这项工作。

回答by Roei Bahumi

This happened to me too. You should specify chunkedMode=false(http://stackoverflow.com/questions/8522729/phonegap-filetransfer-upload-fails-on-android)

这也发生在我身上。您应该指定 chunkedMode=false(http://stackoverflow.com/questions/8522729/phonegap-filetransfer-upload-fails-on-android)

var options = FileUploadOptions();
options.chunkedMode = false;

回答by rand_mem_RAM

This is an unfixed bug in the phonegap library, since there were no bug fixes, i had to get it work by my work around (Basically reupload on every alternate failure):

这是 phonegap 库中的一个未修复的错误,因为没有修复错误,我不得不通过我的工作来让它工作(基本上在每次备用故障时重新上传):

ft.upload(path,
          encodeURI("http://yourdomain.com/upload.php"),
            function(result) {
                alert("Uploaded");
            },
            function(error) {
                ft.upload(path,
                encodeURI("http://yourdomain.com/upload.php"),
                function(result) {
                    alert("Uploaded");                  
                },
                function(error) {
                    alert("Error uploading image");
                },
                { fileName: name, fileKey: "file", mimeType: "image/jpeg", chunkedMode: false }, true);     
            },
            { fileName: name, fileKey: "file", mimeType: "image/jpeg", chunkedMode: false }, true);

回答by Flock Dawson

This could also be a reason, and solved it for me:

这也可能是一个原因,并为我解决了这个问题:

iOS 9 and OSX 10.11 require TLSv1.2 SSL for all hosts you plan to request data from unless you specify exception domains in your app's Info.plist file.

iOS 9 和 OSX 10.11 要求您计划从中请求数据的所有主机都使用 TLSv1.2 SSL,除非您在应用程序的 Info.plist 文件中指定异常域。

(CFNetwork SSLHandshake failed iOS 9)

( CFNetwork SSLHandshake 失败 iOS 9)

回答by Idan Shechter

I've asked Telerik about this issue that I experience with AppBuilder. According to their response it might be a bug in Cordova(I'm using 3.2).

我已经向 Telerik 询问了我在使用 AppBuilder 时遇到的这个问题。根据他们的回复,这可能是 Cordova 中的一个错误(我使用的是 3.2)。

They recommend updating to the latest FileTransfer library(also update all the dependencies) and see if that solves your issue. I actually ran into another problem compiling the new libraries.

他们建议更新到最新的FileTransfer 库(同时更新所有依赖项),看看是否能解决您的问题。我实际上在编译新库时遇到了另一个问题。

I recommend trying that and see if that works for you.

我建议您尝试一下,看看它是否适合您。

回答by Stephen Furlani

You can try either of these:

您可以尝试以下任一方法:

Set android:debuggable="true"in the <application>tag of your AndroidManifest.xmlfile.

android:debuggable="true"在文件的<application>标签中设置AndroidManifest.xml

Set <access origin=".*"/>instead of just the *as it's recommended in the comments section as follows:

设置<access origin=".*"/>而不是*像评论部分推荐的那样,如下所示:

<!-- <access origin="https://example.com" /> allow any secure requests to example.com -->
<!-- <access origin="https://example.com" subdomains="true" /> such as above, but including subdomains, such as www -->
<!-- <access origin=".*"/> Allow all domains, suggested development use only -->