如何使用asiformdatarequest上传图像

时间:2012-05-11 03:51:29

标签: ios image-uploading asiformdatarequest

我打算使用asiformdatarequest.my代码将图像上传到服务器,如:

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);

但是服务器没有返回正确的结果。它可能是什么问题?

1 个答案:

答案 0 :(得分:1)

您没有设置数据 -

[currentRequest setData:imgData forKey:@"file"];