apache / cordova-plugin-file-transfer

Apache Cordova File Transfer Plugin
https://cordova.apache.org/
Apache License 2.0
595 stars 888 forks source link

IOS 13 Upload encounter Error Domain=NSCocoaErrorDomain Code=257 #245

Closed tim70312 closed 4 years ago

tim70312 commented 4 years ago

Bug Report

fileTransfer.upload(...) returns an error with code = 1. Works well with IOS 12.4.

Problem

While calling fileTransfer.upload() to upload a video,it return error code 1

code = 1; source = "file:///private/var/mobile/Containers/Data/PluginKitPlugin/FABA3640-0F94-496D-94BC-85A8ED5241F6/tmp/trim.8466A661-EB72-45FC-9622-4E30AA1C1D3A.MOV"; target = "myService";

What is expected to happen?

Upload data with video successfully to a remote server.(Works well with IOS 12.4)

What does actually happen?

I found the problem is at this line. NSData* fileData = [NSData dataWithContentsOfFile:filePath options:NSDataReadingMappedIfSafe error:&err]; Here's the error log

myapp[1222:123456] Error opening file file:///private/var/mobile/Containers/Data/PluginKitPlugin/FABA3640-0F94-496D-94BC-85A8ED5241F6/tmp/trim.8466A661-EB72-45FC-9622-4E30AA1C1D3A.MOV: Error Domain=NSCocoaErrorDomain Code=257 "The file “trim.8466A661-EB72-45FC-9622-4E30AA1C1D3A.MOV” couldn’t be opened because you don’t have permission to view it." UserInfo={NSFilePath=/private/var/mobile/Containers/Data/PluginKitPlugin/FABA3640-0F94-496D-94BC-85A8ED5241F6/tmp/trim.8466A661-EB72-45FC-9622-4E30AA1C1D3A.MOV, NSUnderlyingError=0x28199f2d0 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}

It seems that apple change the way of dealing NSData

Information

I'm using xcode11 and complie to my IOS 13.1.2 device.

Command or Code

            fileTransfer.upload(_videoURL,  encodeURI(strServerURI), funUploadSuccess, captureError, _videoOption);

Environment, Platform, Device

Testing on iPhone8 with iOS version 12.3.2. iPhoneX with iOS version 12.4.

Version information

MacOS Mojave 10.14.4 XCode 11 Cordova 9.0.0

Checklist

rituparnaGuha commented 4 years ago

Hello I have same issue..unable to upload video from gallery in ionic 3 app.

timbru31 commented 4 years ago

Is this reproducible in a new, plain Cordova app? A minimal reproduction repository would really help to debug and later fix this issue. More information on how to create one: https://github.com/apache/cordova-contribute/blob/master/create-reproduction.md

BekirBesli commented 4 years ago

Hello I have same issue. İ dont undertsand your solve timbru31 ? can you elaborate your description?

BekirBesli commented 4 years ago

https://github.com/apache/cordova-plugin-camera/issues/506#issuecomment-534070130 this work for me .

breautek commented 4 years ago

There's been several reports among plugins that interact with the file system on iOS 13 such as the issue @BekirBesli related to urls returning a /private/ url instead of a /var/ url and I suspect this is the same kind of issue.

tim70312 commented 4 years ago

@BekirBesli You really saved my day. That solution works for me.