【问题标题】:how to upload image by using asiformdatarequest如何使用asiformdatarequest上传图片
【发布时间】:2012-05-11 03:51:29
【问题描述】:

我打算使用 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);

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

【问题讨论】:

    标签: ios image-uploading asiformdatarequest


    【解决方案1】:

    你没有设置数据-

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-13
      • 2016-07-24
      • 2019-05-30
      • 2015-06-03
      相关资源
      最近更新 更多