NSURLSession Background File Upload using Bound Streams - ios

History:
I am working on a project for which we need to support:
Background Upload of files using NSURLSession.
The server expects file to be uploaded using Content-Type: multipart/form-data
Previously, I was using NSURLConnection with bound pair of Streams as depicted in this Apple Sample.
Now, I wish to follow similar approach with NSURLSession(Background Session) by using uploadTaskWithStreamedRequest:.
I have written a small stand-alone iOS Sample + a PHP server to validate my concept.
Problem: Everything works if app stays in foreground, but if during upload I press the home key, the upload fails after some time with error:
Domain=NSURLErrorDomain Code=-997 "Lost connection to background transfer service"
Also a little before the upload fails the Write/Producer Stream's NSStreamEventEndEncountered is encountered.
Note: I know the work-around where I can write whole HTTP Post body to a temp file and use NSURLSession's file upload API instead. But above is more appropriate if I can make it work.
Question: Can anyone guess what could be possible reason for the upload getting failed?
Sample Code: I have uploaded the iOS Sample Code + PHP Server Code to drop box. Here is the CODE
Thanks!

You can't upload streamed tasks using Background Configuration. I successfully upload data only in two cases:
Download task with data stored in request body.
Upload task from file. In that case you will not receive response body.

Related

iOS cannot preview RTF from React PWA

We have a React PWA where we initially download RTF-Documents and save them to an indexDB. We use createObjectURL and an a with a.click() to simulate a download when the file is requested by the User.
The mimetype is set to application/rtf in the createObjectURL call.
However, on iOS (with Safari) the default "view" operation shows the following:
This file cannot be previewed
It might be corrupted or of an unknown file format.
The same file works from our "normal" webapp (i.e. file is served from a backend server). I tried to set the headers exactly like our backend server does, but it either doesn't show the "view" Button at all or it shows the error.
Any ideas how to set up the calls, so iOS will show the RTF correctly?

Processing stuck at 7 percent

I'm trying to upload a video using the API. I can successfully authenticate, upload and create a video and receive a video id. But when I query the processing status using https://api.dailymotion.com/video/{VideoId}?fields=status%2Ctitle%2Cpublishing_progress URL, it keeps returning "publishing_progress": 7 no matter how long I wait.
If I try to upload the same video using the website directly it will process it just fine.
I wonder if anyone else has encountered this issue and know how to solve it.
I think there is an issue with the source URL you associated to the video.
Have you correctly filled the URL field at the video creation (STEP 4.) with the URL returned by the API when you uploaded your video (on STEP 3.)?
If so, you would encourage you to contact our support with more details to dig further into possible issues

react-native-text-detector worked fine in android but why it always returned false in iOS?

First, I used https://github.com/jeanpan/react-native-camera-roll-picker#readme to get an image from photo library, it returned a uri: ph://11A68DD6-A651-462D-BDAB-68FB853ED141/L0/001
Then, I used https://github.com/zsajjad/react-native-text-detector to get text from that image
It worked fine in android but it always returned false in iOS, and I found the following error in console log
NSURLConnection finished with error - code -1002
For more information, the image control can show that image correctly
Here is my source code : https://github.com/haison8x/react-native-test-ocr
Is there any problem with that URI or with application permission?
Due to the sandbox policy of Apple https://developer.apple.com/library/archive/documentation/Security/Conceptual/AppSandboxDesignGuide/AboutAppSandbox/AboutAppSandbox.html, your app cannot read the photo in gallery directly, it will encounter the error: NSURLConnection finished with error - code -1002.
Here is my approach:
Use RNFS.copyAssetsFileIOS copy photo to temp file at your app documents
Use react-native-text-detector to analyze that temp file
The full example is pushed to https://github.com/haison8x/react-native-test-ocr

Dropbox sync api in iOS completedFirstSync remains false

Hi i am using sync api to sync my app data to DropBox. Now i want to list and download(import) images from DBX(i can't use core api because i already used sync api). DBFileSystem only works after first sync complete so i added observer to DBFileSystem its called with completedFirstSync value false. This error also coming
"[ERROR] ERR: DROPBOX_ERROR_NETWORK: cfhttpbinding.c:363: CFHTTP Read Error: (kCFErrorDomainCFNetwork, 2) and completedFirstSync remains false"
In my case user link with DBX then list the images from DBX then download which one they want.
How can i acheive this using sync api?.

Call WCF service from iOS app

*Background:*I have a "document repository" kind-of app.The iOS app calls a WCF service to download the document as well as to get its metadata(document name,document size,etc).There is also a .Net client used for uploading the documents.When I upload a document,I save it in the "AppDomain.CurrentDomain.BaseDirectory" by creating a separate folder for each document.So,effectively,the document is stored at "C:\inetpub\wwwroot\Foo\bar\document.doc".
*The Problem:*when the iOS app tries to download a document,it returns error 500 "Could not find a part of the path 'C:\inetpub\wwwroot\Foo\bar\document.doc'" However,it returns the metadata for the document(document name,document size,document location,etc.) correctly.
What should I do the make the app download the document?
The error 500 was sending back from the server. So the problem is on server side. Are you sure that the path is correct? The uploaded document is on that directory?

Resources