【问题标题】:ASIFormDataRequest returning errorASIFormDataRequest 返回错误
【发布时间】:2011-07-16 12:23:30
【问题描述】:

当我请求服务器上传和 UImage 时遇到问题

    NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/image.jpg"]; //UIImage *img = pickerImage;
    [UIImageJPEGRepresentation(postingImage, 0.5) writeToFile:jpgPath atomically:YES];
    NSData *imageData = UIImageJPEGRepresentation(postingImage, 0.5);
    NSURL *url = [NSURL URLWithString:serverURL];
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];

    [request setData:imageData withFileName:@"image.jpg" andContentType:@"image/jpeg" forKey:@"photo"];

    [request startSynchronous];
    NSLog(@"responseStatusCode %i",[request responseStatusCode]);
    NSLog(@"responseStatusString %@",[request responseString]);

它正在给出这个响应

responseStatusCode 200

responseStatusString 错误:没有上传文件

有谁知道这件事,我在哪里做错了,

非常感谢您的帮助。

谢谢

【问题讨论】:

    标签: iphone upload asihttprequest asiformdatarequest


    【解决方案1】:

    代替

    [request setData:imageData withFileName:@"image.jpg" andContentType:@"image/jpeg" forKey:@"photo"];
    

    试一试

    [request addData:imageData withFileName:@"image.jpg" andContentType:@"image/jpeg" forKey:@"photo"];
    

    我在 ASIHTTPRequest 的帮助下做了同样的事情,并将图像成功发布到服务器上。我猜这应该可以工作,因为它正在我的一个实时项目中工作。

    【讨论】:

    • 谢谢詹尼斯!我试过addData:但它仍然显示“错误:没有上传文件”,这可能是我服务器的问题!?。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-19
    • 2019-09-23
    • 1970-01-01
    • 2017-11-01
    相关资源
    最近更新 更多