【发布时间】:2011-08-06 18:41:58
【问题描述】:
更新:此问题已于 2011 年 5 月 16 日在 phonegap github 存储库中修复。
我有以下 Objective-C 代码:
NSData *photoData = [NSData dataWithContentsOfFile:photoPath];
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"photo-file\"; filename=\"%@\"\r\n", " my-photo.jpg"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: image/jpeg\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:photoData];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
[request addValue:[NSString stringWithFormat:@"%d", body.length] forHTTPHeaderField: @"Content-Length"];
[[NSURLConnection alloc] initWithRequest:request delegate:appDelegate];
[photoData release];
[body release];
[request release];
我正在尝试将图像从 iPhone 发布到使用 node-formidable 的 node.js 服务器。服务器已经可以很好地处理从浏览器发布的图像,但是当我尝试从我的 iPhone 发布时,我收到以下错误:
错误:MultipartParser.end():流 意外结束于 MultipartParser.end (/formidable/1.0.0/package/lib/formidable/multipart_parser.js:301:12) 在 IncomingMessage.anonymous (强大/1.0.0/package/lib/formidable/incoming_form.js:80:30) 在 IncomingMessage.emit (events.js:61:17) 在 HTTPParser.onMessageComplete (http.js:132:23) 在 Socket.ondata (http.js:1001:22) 在 Socket._onReadable (net.js:677:27) 在 IOWatcher.onReadable 作为回调 (net.js:177:10)
图像已正确保存在服务器的临时文件夹中,但在尝试解析表单时会引发错误。
【问题讨论】:
标签: iphone objective-c ios node.js http-headers