How to upload an image using asiformdatarequest

I intend to upload the image to the server using asiformdatarequest.my code, for example:

UIImage *image = [UIImage imageNamed:@"testicon.jpg"];
    NSData *imgData = [[NSData alloc] initWithData:UIImageJPEGRepresentation((image), 0.5)];
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:ADDRESS,myType,action]];

    ASIFormDataRequest *currentRequest = [ASIFormDataRequest requestWithURL:url];
    [currentRequest setPostFormat:ASIMultipartFormDataPostFormat];
    [currentRequest addRequestHeader:@"Content-Type" value:@"multipart/form-data"];
    [currentRequest setRequestMethod:@"POST"];
    [currentRequest setPostValue:@"1" forKey:@"user_id"];


    NSLog(@"responseString = %@",responseString);

but the server does not return the correct result. What is the problem? Maybe this is a problem?

+3
source share
1 answer

You do not set data -

[currentRequest setData:imgData forKey:@"file"];
+1
source

All Articles