Questions tagged [nsurlsessionuploadtask]

The NSURLSessionUploadTask class is a subclass of NSURLSessionDataTask, which in turn is a concrete subclass of NSURLSessionTask. It allows data upload to (web) servers and instances are created using NSURLSession.

The NSURLSessionUploadTask class is a subclass of NSURLSessionDataTask, which in turn is a concrete subclass of NSURLSessionTask. It allows data upload to (web) servers and instances are created using NSURLSession.

The methods associated with the NSURLSessionUploadTask class are documented in NSURLSessionTask Class Reference.

Upload tasks are used for making HTTP requests that require a request body (such as POST or PUT). They behave similarly to data tasks, but you create them by calling different methods on the session that are designed to make it easier to provide the content to upload. As with data tasks, if the server provides a response, upload tasks return that response as one or more NSData objects in memory.

Note: Unlike data tasks, you can use upload tasks to upload content in the background. (For details, see URL Loading System Programming Guide.)

When you create an upload task, you provide an NSURLRequest or NSMutableURLRequest object that contains any additional headers that you might need to send alongside the upload, such as the content type, content disposition, and so on.

While the upload is in progress, the task calls the session delegate’s URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend: method periodically to provide you with status information.

When the upload phase of the request finishes, the task behaves like a data task, calling methods on the session delegate to provide you with the server’s response—headers, status code, content data, and so on.

Reference:

143 questions
3
votes
0 answers

iOS background upload - how to handle expired auth token

I am performing background uploads to an endpoint that requires authorization using a token. The token is included as an HTTP header to the individual upload tasks that are created/started. Is it possible to respond to expired token messages and…
Zach
  • 3,261
  • 5
  • 18
  • 42
3
votes
2 answers

Background upload of large amount of data

I need to upload large number of photos to a server from my iOS device. For example, 500 photos. How should I do this right? I created upload task with background session configuration with NSURLSession for each photo. I tried making my own custom…
3
votes
3 answers

iOS - How to upload a video with uploadTask?

I need to upload an mp4 video file from iPhone/iPad to a server, also in the background, so I read that is possible with URLSession.uploadTask(with: URLRequest, fromFile: URL) method, but I don't understand how do I prepare the request before.I need…
Roran
  • 403
  • 4
  • 19
3
votes
2 answers

using begin​Background​Task​With​Expiration​Handler​ for upload

From the doc it looks like uploading a file is a good use case for using begin​Background​Task​With​Expiration​Handler​. I've found that using let uploadTask = session.uploadTask(with: request as URLRequest, fromFile: file) uploadTask.resume() will…
3
votes
0 answers

NSURLSession background upload completion method called twice after restart

I am using NSURLSession in background mode, to upload images from file using a NSURLSessionUploadTask, and the delegate callbacks. All this works perfectly fine if the app remains on the background as opposed to getting killed by the user. However…
Oscar Gomez
  • 18,102
  • 12
  • 80
  • 113
3
votes
1 answer

can NSURLProtocol work with NSURLSession {upload, download}dataTask

I have a custom NSURLProtocol #import @interface XXXURLProtocol : NSURLProtocol @property (nonatomic, strong) NSURLSession *session; @property (nonatomic, strong)…
3
votes
1 answer

Share image using share extension

While sharing an image with a share extension, I am facing an issue. I have done all the steps that enable the app group in both the extension and the container profile. I followed these steps to implement sharing code in the extension. The error…
TamilKing
  • 1,633
  • 11
  • 22
3
votes
1 answer

Not sure what happens to my apps objects when using NSURLSession in background - what state is my app in?

More of a general question - I don't understand the workings of NSURLSession when using it in "background session mode". I will supply some simple contrived example code. I have a database which holds objects - such that portions of this data can be…
3
votes
1 answer

uploading NSData using AFNetwork terminating my APP

I'm trying to upload a NSData which is image using AFNetwork but something going wrong which i cannot find where is my mistake here is my code: NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:@"test.jpg"],…
3
votes
1 answer

Does NSURLSession support FTP upload?

I want to upload files to an FTP. I would like to use NSURLSession for its backgrounding support. Apple documentation says it is supported but so far I have been unable to find it. The POC I have done is as follows: The sample code from apple here…
Rick
  • 1,066
  • 1
  • 18
  • 26
2
votes
1 answer

NSURLSession resulting in 0B images uploaded to GCS

I am using a NSURLSession configured as a background session to upload multiple images to a bucket in GCS. For one test, 26 images were used, each around 10 MB each. The tests are performed with strong wifi connectivity and battery close to 100%…
FishStix
  • 4,560
  • 8
  • 34
  • 50
2
votes
1 answer

iOS: didCompleteWithError, didReceive Response not triggered with URLSession.uploadTask

I would like to add a progress bar for knowing exactly the percent of upload of my video, but impossible to call the didCompleteWithError, didReceive response, didSendBodyData bytesSent: Int64, totalBytesSent: Int64, totalB etc... I added well the…
ΩlostA
  • 2,152
  • 4
  • 19
  • 47
2
votes
1 answer

NSURLSession error when uploading on WiFi: NSURLErrorDomain Code=-999

I built an app, more than an year ago, that provides photo sharing and video sharing for its users. It ran without any problems until a couple of weeks ago where I introduced a new feature: the possibility of marking a video to be uploaded only when…
2
votes
0 answers

Suspended NSURLSessionUploadTask resume when applicationWillEnterForeground for the second time

i created a NSURLSessionUploadTask task private lazy var uploadSession: NSURLSession = { let sessionConfiguration = NSURLSessionConfiguration.backgroundSessionConfigurationWithIdentifier("com.foo.bar") …
Bar
  • 543
  • 1
  • 6
  • 19
2
votes
2 answers

NSURLSessionUploadTask get response data

I have some misunderstanding in using NSURLSession framework, that's why I decided to write small app from scratch without AFFramework/Alamofire. I have an API that requires following steps to upload file: POST file data Get response (JSON) Post…
user1284151
  • 835
  • 4
  • 11
  • 21
1
2
3
9 10