nsurlsessionuploadtask

Convert NSURLConnection to NSURLSessionUploadTask example

孤人 提交于 2019-12-31 03:07:25
问题 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 key "photo". Below I have an working example written in NSURLConnection and I will like to convert it into NSURLSession. As I read on the apple documentation from what I understood I should use a Data tasks because in my case it is an image and if

URLSessionUploadTask getting automatically cancelled instantly

这一生的挚爱 提交于 2019-12-30 06:29:49
问题 I'm having this weird issue in which a newly created URLSessionUploadTask gets cancelled instantly. I'm not sure if it's a bug with the current beta of Xcode 8. I suspect it might be a bug because the code I'm about to post ran fine exactly once. No changes were made to it afterwards and then it simply stopped working. Yes, it literally ran once, and then it stopped working. I will post the error near the end. I will post the code below, but first I will summarize how the logic here works. My

Why does NSURLSession uploadTaskWithRequest:fromData: fail to upload to php server?

*爱你&永不变心* 提交于 2019-12-21 17:32:56
问题 The php code works fine. Ive uploaded files from a html form on the same server. The files uploaded ranged from 40K to 2.0M so its not size. File uploads is activated on the server running PHP 5.3 I found many posts such as this one (without an answer yet):https://stackoverflow.com/questions/19710388/using-nsurlsession-to-upload-an-image. This one uses uploadTaskWithRequest:fromFile: instead of fromData:NSURLSession make sure Upload worked This is NSURLSessionDataTask instead of

Send data and parameter to server

风格不统一 提交于 2019-12-12 06:36:17
问题 I have this code here that send a data to my server, this code works very well: NSString *imagepath = [[self applicationDocumentsDirectory].path stringByAppendingPathComponent:@"ProgrammingWithObjectiveC.pdf"]; NSURL *outputFileURL = [NSURL fileURLWithPath:imagepath]; NSURL *icyURL = [NSURL URLWithString:uploadURLString]; NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:icyURL]; [request setHTTPMethod:@"POST"]; NSURLSessionConfiguration *sessionConfig =

NSURLSessionUploadTask is not calling delegate method with NSURLSessionConfiguration backgroundSessionConfiguration

*爱你&永不变心* 提交于 2019-12-12 04:40:01
问题 I am trying upload image using backgroundSessionConfiguration and NSURLSessionUploadTask to keep live upload process in application background mode. But when i use backgroundSessionConfiguration , NSURLSessionUploadTask is not calling delegate method while using defaultSessionConfiguration it call delegate method. Here is the code. //Create a file to upload UIImage *image = [UIImage imageNamed:@"1.jpg"]; NSData *imageData = UIImagePNGRepresentation(image); NSFileManager *fileManager =

How to hit post request with NSDictionary as parameter

橙三吉。 提交于 2019-12-11 18:54:42
问题 I am trying to hit post type sending dictionary as parameter. Below is what i tried so far, but i think format sending is not generating correctly. Please guide, code is below: Data fetching which need to send as parameter: NSArray *routesLegsArray = [[[[[json objectForKey:@"routes"]objectAtIndex:0] objectForKey:@"legs"] objectAtIndex:0] objectForKey:@"steps"]; NSMutableArray *arrSteps = [[NSMutableArray alloc] init]; for(int i=0; i<[routesLegsArray count]; i++) { if ([routesLegsArray count]

Upload image to server through POST method ios

廉价感情. 提交于 2019-12-11 12:22:51
问题 I want to upload image to server through post method. The format should be like ["ImageName"=Image] . I have tried the following code but it doesn't upload the image to server. Can anyone help me ? -(void)SaveImageToServer:(UIImage*)getImage :(NSString*)imageName :(NSString*)getUrlToSaveImg withCompletionBlock:(void(^)(NSMutableArray *))completionBlock { NSMutableArray *arrrrr=[[NSMutableArray alloc]init]; NSMutableURLRequest *reqqq=[[NSMutableURLRequest alloc]initWithURL: [NSURL

One progress bar for multiple file upload

天涯浪子 提交于 2019-12-11 10:54:02
问题 I'm trying to upload 2 images(one at a time)using NSURLSessionTask. - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didSendBodyData:(int64_t)bytesSent totalBytesSent:(int64_t)totalBytesSent totalBytesExpectedToSend:(int64_t)totalBytesExpectedToSend { if (self.imageName1 != nil && self.imageName2 != nil) { float progress = (float)totalBytesSent / (float)totalBytesExpectedToSend; if (progress != 1.00) { // Calculate total bytes to be uploaded or the split the progress

iOS - How to upload a video with uploadTask?

醉酒当歌 提交于 2019-12-11 06:02:05
问题 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 to create a multipart/form-data request because I want to append other string parameters. func requestBodyFor(video: URL) -> Data? { let url = URL(string: "url_of_upload_handler.php")! let parameters = ["type":"video", "user":"112"] do { let

Resume upload task using NSURLSessionUploadTask after app is killed?

一世执手 提交于 2019-12-11 00:15:14
问题 I am using the following code to upload image using NSURLSessionUploadTask NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration]; NSURL *URL = [NSURL URLWithString:@"http://example.com/upload"]; NSURLRequest *request = [NSURLRequest requestWithURL:URL]; NSURL *filePath = [NSURL fileURLWithPath:@"file://path/to/image.png"]; NSURLSessionUploadTask