Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NSData *imgData = UIImagePNGRepresentation(image);
- NSDictionary *aParametersDic; // It's contains other parameters.
- NSURL *url = [NSURL URLWithString:urlString];
- NSMutableURLRequest *request= [[NSMutableURLRequest alloc] initWithURL:url] ;
- [request setURL:[NSURL URLWithString:urlString]];
- [request setHTTPMethod:@"POST"];
- NSString *boundary = @"---------------------------14737809831466499882746641449";
- NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
- [request addValue:contentType forHTTPHeaderField: @"Content-Type"];
- NSData *jsonData = [NSJSONSerialization dataWithJSONObject:json options:kNilOptions error:nil];
- NSMutableData *postbody = [NSMutableData data];
- NSString *postData = [self getHTTPBodyParamsFromDictionary:aParametersDic boundary:boundary];
- [postbody appendData:[postData dataUsingEncoding:NSUTF8StringEncoding]];
- [postbody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
- [postbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"file\"; filetype=\"image/png\"; type=\"file\"; filename=\"%@\"\r\n", @"church.jpg"] dataUsingEncoding:NSUTF8StringEncoding]];
- [postbody appendData:[@"Content-Type: image/jpeg\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
- [postbody appendData:[NSData dataWithData:imgData]];
- [postbody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
- [postbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"data\"; filetype=\"application/json\"; type=\"file\"; filename=\"%@\"\r\n", @"json.josn"] dataUsingEncoding:NSUTF8StringEncoding]];
- [postbody appendData:[@"Content-Type: application/json\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
- [postbody appendData:[NSData dataWithData:jsonData]];
- [postbody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
- [request setHTTPBody:postbody];
- [[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
- NSString *returnString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
- NSLog(@"%@\nerror: %@", response, error);
- }] resume];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement