I want to upload the image to the server too, but got an error while doing this
I used the following code, but I donβt know what is wrong there.
+(void) HTTPPostImage:(NSString *) stringURL andParameter:(NSData *) imageData andSelector:(SEL) selector andTarget:(id) target{ AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:[NSURL URLWithString:stringURL]]; // NSData *imageData = UIImageJPEGRepresentation(self.avatarView.image, 0.5); NSDictionary *parameters =NULL; NSString *myUUID = [[NSUUID UUID] UUIDString]; // create a UUID NSLog(@"myUUID%@",myUUID); AFHTTPRequestOperation *op = [manager POST:@"" parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { [formData appendPartWithFileData:imageData name:@"public.image" fileName:@"photo.jpg" mimeType:@"image/jpeg"]; //[formData appendPartWithFileData:imageData name:@"file" fileName:myUUID mimeType:@"image/jpeg"]; } success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"Success: %@ ***** %@", operation.responseString, responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@ ***** %@", operation.responseString, error); }]; [op start]; }
I do not know what is wrong with this parameter
[formData appendPartWithFileData:imageData name:@"public.image" fileName:@"photo.jpg" mimeType:@"image/jpeg"];
For server parameter
I donβt know if I made mistakes or the server did it

ios objective-c afnetworking-2
nischal hada Oct. 20 '15 at 5:44 2015-10-20 05:44
source share