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:

152 questions
2
votes
2 answers

Will temporary files be saved by an NSURLSessionUploadTask

I am implementing a resumable upload protocol that uploads in the background on iOS, which means I have to use an NSURLSessionUploadTask with a file. Since it's a resumable upload protocol, the file needs to be truncated based on the data that has…
JustinHK
  • 758
  • 1
  • 6
  • 19
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
  • 603
  • 1
  • 7
  • 19
2
votes
3 answers

TaskIdentifier in NSURLSession not Changing

I am trying to upload multiple videos through NSURLSession in my App. But taskIdentifier for every request is coming same. Its not getting change for every request. How can we keep track for our request? How can we know which one gets complete? This…
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
  • 875
  • 4
  • 12
  • 23
2
votes
0 answers

Resume upload task using NSURLSessionUploadTask after app is killed?

I am using the following code to upload image using NSURLSessionUploadTask NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; AFURLSessionManager *manager = [[AFURLSessionManager alloc]…
2
votes
0 answers

Upload file with NSURLSessionUploadTask in back ground

i am uploading multiple files using NSURLSessionUploadTask. I want to run same process in back ground and it works fine for current file. App is not suspended until current file got uploaded successfully. Now, when second files comes to upload, it…
Pratik Patel
  • 1,393
  • 12
  • 18
2
votes
0 answers

NSURLSessionUploadTask request pause and resume causes 400

While app goes to background, I pause the the upload task for Amazon S3 and then resuming the same task on foreground. This causes sometimes NSURLSession's delegate method didCompleteWithError:(NSError *)error to throw 400 and error as nil and fails…
Kalaivani
  • 424
  • 4
  • 20
2
votes
1 answer

Convert NSURLConnection to NSURLSessionUploadTask example

Hi everyone and thanks in advance for any help providing in understanding in how to convert some NSURLConnection code into the newer NSURLSession. What I am trying to do is to make a POST request to a server, and send a photo base 64 encoded for the…
2
votes
2 answers

Issue while uploading Image

Step 1: here I am creating the Request NSMutableURLRequest *request1 = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" …
2
votes
2 answers

NSURLSessionUploadTask don't upload image with parameters

I have this code below which sends an image and some text to my server: NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration]; self.session = [NSURLSession sessionWithConfiguration:…
LettersBa
  • 747
  • 1
  • 8
  • 27
2
votes
2 answers

Upload with Buffer iOS 7

I am trying to implement an Upload with random Data and measure the speed. For now i am generating my random NSData like this: void * bytes = malloc(""); NSData * myData = [NSData dataWithBytes:bytes length:"bytes"]; free("bytes"); But there will…
davidOhara
  • 1,008
  • 5
  • 17
  • 39
1
vote
0 answers

BackgroundSession FAILED to UNLINK download file when starting an uploadTask with background URLSession

I'm using a background URLSession to upload two files. The task is created via: let backgroundTask = self.session.uploadTask(with: request, fromFile: src) backgroundTask.resume() The task for the first task encountered an error like…
user1783732
  • 1,599
  • 5
  • 22
  • 44
1
vote
2 answers

Upload file error handling using URLSessionConfiguration.background and uploadTask

I am using URLSessionConfiguration.background and uploadTask to upload a file from an iOS app. The upload session is configured in the following way: let configuration = URLSessionConfiguration.background(withIdentifier:…
cristallo
  • 1,951
  • 2
  • 25
  • 42
1
vote
0 answers

File getting corrupted if user cancels file UPLOAD on WEBDAV repository

In one of my iOS app, I'm trying to upload a file on WEBDAV repository and this is how I'm preparing things for UPLOAD - func createUploadRequest(url: String) -> URLRequest? { if let url = URL(string: url) { var request =…
Suryakant Sharma
  • 3,852
  • 1
  • 25
  • 47
1
vote
0 answers

Best place to call `completionHandler` received in `handleEventsForBackgroundURLSession` in case of uploading?

I am using URLSessionConfiguration.background for uploading and downloading content while my app is not foreground. The code that I'm using to create a background session is as below: private var session: URLSession! private override init()…
1 2
3
10 11