ASIFormDataRequest:“路径中没有文件”,而它确实存在

时间:2011-08-04 18:32:56

标签: iphone objective-c ios asiformdatarequest

我正在尝试使用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"

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

任何人都有线索?

谢谢!

2 个答案:

答案 0 :(得分:0)

我怀疑是%20会造成麻烦。尝试取消filePath变量:

filePath =  [filePath stringByReplacingPercentEscapesUsingEncoding:NSASCIIStringEncoding];

答案 1 :(得分:0)

尝试使用POSIX路径:

[request setFile:[[NSURL URLWithString:filePath] path] forKey:@"database"];