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
1
vote
1 answer

NSUrlSession: is it possible to upload files in the background?

Using NSUrlSession with a background configuration let's me download files even if the app gets terminated by iOS. Being curious, I tried to add an upload task and noticed that it won't continue, even not if the app is only suspended. Apple talks…
Krumelur
  • 32,180
  • 27
  • 124
  • 263
1
vote
1 answer

UI Slow to Update *ONLY* If Called In Response To Change Occurring in NSURLSessionUploadTask Completion Block

The app interacts with php scripts on my server. A user can create a booking, and details are written to a database. Subsequently, they can cancel that booking. Within the app, a booking is an object, responsible for gathering its own details from…
1
vote
1 answer

NSURLSession background session callbacks on app termination

I am using below code to create background session for huge uploads, NSURLSessionConfiguration *config = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:identifier]; NSURLSession *session = [NSURLSession…
nmhmd
  • 11
  • 4
1
vote
1 answer

Should I save UIImage to file before upload?

I am implementing a photo uploader in Swift. After getting a UIImage from a UIImagePickerController, I will resize the image, perhaps to be less than 100 KB. Then, I will convert the UIImage to data using UIImageJPEGRepresentation(). Should I then…
ma11hew28
  • 121,420
  • 116
  • 450
  • 651
1
vote
1 answer

Is there any way to enable NSURLSession to run more than 4 NSURLSessionUploadTasks concurrently?

When I create and start 20 NSURLSessionUploadTasks only 3-4 will run at anyone time, even when HTTPMaximumConnectionsPerHost is set to 20! I understand that I can limit the number of max uploads very easily with HTTPMaximumConnectionsPerHost.…
1
vote
0 answers

How should I save data while is uploading some data with NSURLSession and the app is suspended?

I am developing an app where I have to upload an entity with its relation. (I think this is similar to dropbox files uploading) This entity is called PlaceEntity and has a relation with PictureEntity (to many). I want to do it using NSURLSession to…
croigsalvador
  • 1,993
  • 2
  • 24
  • 47
1
vote
0 answers

Why NSURLSessionUploadTask suspend method doesn't work and still retrieving data from the server?

this is my problem: I have a registration UIViewController so the user can send his information via POST. When the user taps "send", I instantiate a NSURLSessionUploadTask using the NSURLSession uploadTaskWithRequest:fromData:completionHandler:…
1
vote
2 answers

Background Upload With Stream Request Using NSUrlSession in iOS8

Previously in iOS7 when we try to upload with stream request in background we get following exception Terminating app due to uncaught exception 'NSGenericException', reason: 'Upload tasks in background sessions must be from a file' But in iOS8 there…
1
vote
0 answers

NSURLSession file transfer restarted?

I am using NSURLSession for uploading a file with background transfer service, but after uploading few bytes. NSURLSession starts upload again, Don't know exactly why NSURLSession restart and send the same bytes to the server which are already…
1
vote
1 answer

NSURLSessionUploadTask offset file upload on retry

I have to design something that reacts to connectivity loss to the server and supports uploading in the background on iOS. If the upload fails due to a connectivity loss, it should start again from the offset where it failed. I have the ability to…
cynistersix
  • 1,215
  • 1
  • 16
  • 30
1
vote
0 answers

Uploading images to s3 bucket and then uploading images' links to my server in background

I have a generic question, experienced developers may laugh at me when they read that but I couldn't manage it somehow. Basically, I want to upload images from filesystem to my amazon s3 bucket and after that upload links of these images to my…
1
vote
1 answer

Uploading file using NSURLSessionUploadTask to PHP server

I have a video upload system in an iOS app using NSURLSessionUploadTask. The video file is saved to an NSURL so I am using the following code in my upload method: request.HTTPMethod = @"POST"; [request addValue:@"file"…
GTF
  • 8,031
  • 5
  • 36
  • 59
1
vote
3 answers

Send UIImage POST to server from UIImagePickerController?

I am trying to send a UIImage take with the UIImagePickerController to a server POST along with other pertinent values. But I get at the line that tries to set the dictionary value @"image" to UIImageJPEGRepresentation(image,…
izk
  • 1,189
  • 2
  • 8
  • 23
1
vote
1 answer

Is uploading a file using a download task for background transfert a good thing?

I need to upload files in background for my application. So i looked uploadtask method but it actually need a fileurl to work with background transfert. It won't really be a big deal to put my object in JSON/XML and save it as a file but it would…
1
vote
1 answer

Upload photos in background in iPad using NSURLSession

What is the best method to upload multiple photos from the asset library using NSURLSessionUploadTask? I'm now using NSURLSession background uploads. Here's the code I'm using: NSArray *paths =…
humblePilgrim
  • 1,818
  • 4
  • 25
  • 47