Ionic android - 使用预签名URL将文件上传到S3(错误代码:3) [英] Ionic android - Upload file to S3 using presigned URL (Error code: 3)
问题描述
我正在尝试使用预先签名的URL将图像从离子应用程序上传到S3。
I am trying to upload image from ionic application to S3 using presigned URL.
这是目前的情况:
离子应用程序向服务器发送请求以从AWS S3获取预先签名的上传URL 。
Ionic application sends request to server to get presigned upload URL from AWS S3.
在服务器端,我有一个节点应用程序正在使用aws-sdk获取预签名URL,然后将其返回给客户端。
On server side I have a node application that is using aws-sdk to get presigned URL and then returns it back to client.
这是我在Ionic方面的代码,应该将文件上传到AWS
This is my code on Ionic side that should upload file to AWS
var options = {
fileKey: 'file',
fileName: fileName,
mimeType: 'image/jpeg',
chunkedMode: false,
timeout: 300000,
httpMethod:'PUT',
encodeURI: false,
headers: {
'Content-Type': 'image/jpeg'
}
};
var ft = new FileTransfer();
ft.upload(cordova.file.dataDirectory + fileName, uploadLink, function () {
console.log("image uploaded");
}, function (err) {
console.log(err);
}, options);
此代码适用于iOS设备,但是当我将应用程序部署到Android时并尝试上传文件失败,并出现以下错误:
This code works on iOS device, but when I deploy application to Android and try to upload file it fails with the following error:
FileTransferError body:null code:3 exception:写入错误:
ssl = 0x8ec63f80:系统调用期间的I / O错误,连接重置为
peerhttp_status:null source:
file:///data/user/0/com.ionicframework.xxxxxxxx/files /xxxxx.jpg
target: https://xxxxxx.s3.eu-central- .....
离子信息
Cordova CLI:6.4.0
离子CLI版本:2.1.12
Ionic App Lib版本:2.1.7
Ionic info Cordova CLI: 6.4.0 Ionic CLI Version: 2.1.12 Ionic App Lib Version: 2.1.7
设备上的Android版本为6.0
Android version on device is 6.0
我有点困惑,因为它在iOS上工作,但它不适用于Android。我之前使用过cordova文件传输,但从未遇到类似情况。然而,这是我第一次直接从android上传文件到S3。
I am a bit confused as it is work on iOS but it doesn't work on android. I have used cordova file transfer before and have never run into similar situation. However this is the first time that I am uploading files from android to S3 directly.
任何帮助都将受到高度赞赏。
Any help would be highly appreciated.
推荐答案
好的,不确定究竟是什么问题,但问题肯定是最新版本的cordova-plugin-文件传输插件(此时为1.6.0)。此问题仅反映在Android平台上。
Ok, not sure what exactly is a problem, but the issue is definitely with the latest version of the cordova-plugin-file-transfer plugin (at this moment it is 1.6.0). This issue only reflects on android platform.
我已经安装了旧版本的插件(1.5.1),修复了这个问题。我做了什么来解决我的问题:
I have installed older version of the plugin (1.5.1) which "fixed" the issue. What I did to resolve my issue:
1)安装最新版本的cordova npm install -g cordova
1) install latest version of cordova npm install -g cordova
2)安装最新版本的离子 npm install -g ionic
2) install latest version of ionic npm install -g ionic
3)更新android平台离子平台更新android
3) update android platform ionic platform update android
4)删除插件离子插件删除cordova-plugin-file-transfer
5)安装以前版本的插件 ionic plugin add cordova- plugin-file-transfer@1.5.1
5) install previous release of plugin ionic plugin add cordova-plugin-file-transfer@1.5.1
6)保存对package.json的更改离子状态保存
6) save changes to package.json ionic state save
7)离子运行android
我希望它对某些人有用。
I hope it will be useful for somebody.
这篇关于Ionic android - 使用预签名URL将文件上传到S3(错误代码:3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!