Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert file path to file url[NSUrl]

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.

[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

Error: @"NSLocalizedFailureReason" : @"Expected URL to be a file URL"

Questions: How to convert this path string to file url?

like image 205
Mani Avatar asked Mar 26 '14 05:03

Mani


People also ask

Can a file path be a URL?

1 Answer. Show activity on this post. file is a registered URI scheme (for "Host-specific file names"). So yes, file URIs are URLs.

What does Nsurl mean?

An NSURL object is composed of two parts—a potentially nil base URL and a string that is resolved relative to the base URL. An NSURL object is considered absolute if its string part is fully resolved without a base; all other URLs are considered relative.

What is the URL for a file on my computer?

To obtain a file or folder's URL, to the right of the file or folder, from the Actions drop-down menu, select Edit Details. This displays the Edit Details page for the item.


2 Answers

You want to use this method instead:

+ (id)fileURLWithPath:(NSString *)path
like image 112
Gerd K Avatar answered Oct 01 '22 13:10

Gerd K


Try in this way.

 NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];

    //OR ... Use `

 +[NSURL fileURLWithPath:]

OR take a look at NSURL Class Reference

Hope it helps you.

like image 26
Vidhyanand Avatar answered Oct 01 '22 14:10

Vidhyanand