0

我正在尝试使用 ASIFormDataRequest 上传文件

ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString: uploadUrl]] autorelease];
[request setPostValue:md5sum forKey:@"md5sum"];
[request setFile:[NSString stringWithFormat:@"%@", filePath] forKey:@"database"];
[request startSynchronous];

这会记录一个错误:

"No file exists at: file://localhost/Users/thomas/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/36115C00-9352-4CD4-B5C2-C3A1CD6041FF/Documents/foo.sqlite"

但是,当我在浏览器中尝试路径时。它会立即下载文件,因此该文件确实存在。

有人有线索吗?

谢谢!

4

2 回答 2

0

我怀疑这%20是制造麻烦的原因。尝试取消转义filePath变量:

filePath =  [filePath stringByReplacingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
于 2011-08-04T18:43:52.737 回答
0

尝试使用 POSIX 路径:

[request setFile:[[NSURL URLWithString:filePath] path] forKey:@"database"];
于 2011-08-04T18:47:16.663 回答