【发布时间】:2011-12-26 18:03:04
【问题描述】:
在客户端我使用 ASIHttpRequest 上传图片:
// upload on server
NSLog(@"Upload to server");
UIImage *im = [UIImage imageNamed:@"ok.png"];
NSData *da = UIImageJPEGRepresentation(im, 0.6);
NSLog(@"DATA:%@", da);
NSString *n = [NSString stringWithFormat:@"%@/upload", @"http://localhost:3000"];
NSURL *url = [NSURL URLWithString:n];
NSLog(@"URL:%@",url);
ASIFormDataRequest *r = [ASIFormDataRequest requestWithURL:url];
[r setData:da
withFileName:@"myphoto.ico"
andContentType:@"image/jpeg"
forKey:@"photo"];
[r setRequestMethod:@"POST"];
[r setShouldAttemptPersistentConnection:NO];
[r startSynchronous];
NSString *resp = [r responseString];
NSLog(@"RESPONSE:%@", resp);
在服务器端,我使用 node.js:
app.post('/upload', function(req, res){
console.log(req);
console.log(req.params);
});
客户端的请求似乎没问题,但是在检查服务器端的日志时,我看不到任何与我发送的数据相关联的东西。在这种情况下,在 node.js 上检索数据的正确方法是什么?
【问题讨论】:
标签: node.js asihttprequest express