I'm trying to convert the data from a .obj file to a base64 string, so that I can display a thumbnail preview of the .obj file in an NSImageView
.
Below is my code for getting the asset from a local url, and converting it to a base64 string. I then convert that to Data
, which I then attempt to convert to an image.
let fileUrl = Foundation.URL(string: input_string)
let data: NSData? = NSData(contentsOfFile: input_string)
if let fileData = data {
let base64String = fileData.base64EncodedString()
let decodedData = NSData(base64Encoded: base64String, options: NSData.Base64DecodingOptions(rawValue: 0) )
let decodedimage = NSImage(data: decodedData! as Data)
}
I can see that I'm getting the data set, but decodedImage
is always nil - I'm guessing this has something to do with .obj image format, which I may not know enough about. Any insight / help appreciated.
EDIT: Here's a screenshot showing what the .obj file looks like in the finder preview.