ios 将文件路径转换为文件 url[NSUrl]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22652210/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert file path to file url[NSUrl]
提问by Mani
I'm try to file upload operation using AFNetworking
multi-part form data. I'm getting following error. I could find out what is error.
我正在尝试使用AFNetworking
多部分表单数据进行文件上传操作。我收到以下错误。我可以找出什么是错误。
[NSURL URLWithString:filePath]
Also used [[NSURL URLWithString:filePath] filePathURL]
, But doesn't help me.
When I log filepath string: It shows correct path : /var/mobile/Applications/3CBF5127-B2FF-49C3-AC98-16BD0886EEE7/Documents/20140326105108_slno.ma4
[NSURL URLWithString:filePath]
也用过[[NSURL URLWithString:filePath] filePathURL]
,但对我没有帮助。当我记录文件路径字符串时:它显示正确的路径:/var/mobile/Applications/3CBF5127-B2FF-49C3-AC98-16BD0886EEE7/Documents/20140326105108_slno.ma4
Error:@"NSLocalizedFailureReason" : @"Expected URL to be a file URL"
错误:@"NSLocalizedFailureReason" : @"Expected URL to be a file URL"
Questions:
How to convert this path string to file url
?
Questions:
如何将此路径字符串转换为file url
?
回答by Gerd K
You want to use this method instead:
您想改用此方法:
+ (id)fileURLWithPath:(NSString *)path
回答by Vidhyanand
Try in this way.
用这种方法试试。
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];
//OR ... Use `
+[NSURL fileURLWithPath:]
OR take a look at NSURL Class Reference
或者看看NSURL 类参考
Hope it helps you.
希望对你有帮助。