似乎无论我在iOS上做什么,我的文件传输都会超时 . 我目前没有Android设备进行测试,但截至昨天它正在运行 . 我安装了文件传输插件和白名单 .
Ionic Framework版本:2.0.0-beta.8,离子CLI版本:2.0.0-beta.30,Ionic App Lib版本:2.0.0-beta.16 Xcode版本:Xcode 7.3.1
这是我的代码:
upload = (image: string) : void => {
let ft = new Transfer();
let filename = image.substr(image.lastIndexOf('/')+1)+'.jpg';
let options = {
fileKey: 'file',
fileName: filename,
mimeType: 'image/jpeg',
chunkedMode: false,
headers: {
'Content-Type' : undefined
},
params: {
fileName: filename,
apikey: "mykey"
}
};
ft.upload(image, "https://api.ocr.space/parse/image", options, false)
.then((result: any) => {
this.success(result);
}).catch((error: any) => {
this.failed(error);
});
}
它每次超时并给出这个结果:
[6311:2681244] -[CDVFileTransfer requestForUploadCommand:fileData:]
[Line 224] fileData length: 68706
[6311:2682532] FileTransferError {
body = "";
code = 3;
"http_status" = 0;
source = "file:///var/mobile/Containers/Data/Application/372A03D7-653A-45D8-B59A-EA34252E4AF3/tmp/cdv_photo_006.jpg";
target = "https://api.ocr.space/parse/image";
}
[6311:2682532] File Transfer Error: The request timed out.
2 回答
对于iOS 9及更高版本,您需要在发布之前在XCode中添加AppTransportSecurity以允许与HTTP连接 . 在XCode中,在info.plist中添加一些键 . 我遵循的步骤是:
打开我的Projects info.plist文件
添加了一个名为NSAppTransportSecurity的密钥作为字典 .
添加了一个名为NSAllowsArbitraryLoads的子键作为布尔值,并将其值设置为YES . 或者使用以下代码更改info.plist:
您需要使用自己的URL更改yourserver.com以进行文件传输
它似乎是 endpoints 的一个问题 . 这是任何人看的woking上传代码的副本 .