Convert file path to file url[NSUrl]

32,163

Solution 1

You want to use this method instead:

+ (id)fileURLWithPath:(NSString *)path

Solution 2

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.

Share:
32,163
Mani
Author by

Mani

Working as Sr. IOS Engg at MVI Technology with 9+ exp. Experience in Swift, Objective-C, Android. Worked with Rolo for Android @ Netmine Mobile Innovations. I've published Tattle-UI-IOS control. It is an testing kit used to beta-tester for reporting UI issue by marking on current screen's snapshot.(like UI misalignment, font..etc). Earned Marshal badge at No.884.

Updated on July 31, 2022

Comments

  • Mani
    Mani almost 2 years

    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?