Anshul Kabra
Anshul Kabra

Reputation: 199

How to get the NSData from a file path in KMM?

Currently, I am building the app in KMM, which has a feature to capture images. Once the image is captured got the URL of the file, and then I am saving the path in SqlDelight DB.

I tried to save both paths, i.e URL.path as well as URL.absoluteString.

Now to sync the stored path to the server I need to get the byte Array of these images, to get the byte Array, First I need to get the NSData from the path.

But it's always returning as null. My current actuals for iOS inside common code is -

NSData.create(contentsOfFile = filePath) -- > null

NSFileManager().contentsAtPath(filePath) -- > null

The above method is always returning null for the NSData, but when I am accessing the same URL.path inside the swift module, it is able to get the NSData object.

let data = NSData(contentsOfFile: imagePath) -> getting the NSData

Please help me to get the NSData object inside the common code, or any other alternative, except I don't want to store the byte array in DB.

Upvotes: 2

Views: 858

Answers (0)

Related Questions