ASIFormDataRequest 返回错误

发布于 2024-11-24 18:37:59 字数 882 浏览 2 评论 0原文

当我请求服务器上传并且 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]);

给出此响应

时,我遇到问题

响应状态代码 200

responseStatusString 错误:未上传文件

有谁知道这一点,我在哪里做错了,

非常感谢您的帮助。

谢谢

I am getting a problem when i request to the server to upload and 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]);

it is giving this responses

responseStatusCode 200

responseStatusString Error: No file uploaded

Do any one know about this, where i am doing mistake,

your help is much appreciated.

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

穿透光 2024-12-01 18:37:59

而不是

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

尝试

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

像我一样在 ASIHTTPRequest 的帮助下 并成功地将图像发布到服务器上。我想这应该有效,因为它正在我的一个实时项目中工作。

Instead of

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

Try as

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

I did same with help of ASIHTTPRequest and get images successfully posted on server. This should work I guess as it is working in one of my live project.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文