Question

I have NSData received from server for which i don't know the MIME type.

Now i want to convert the NSData into any file like Image/Pdf without knowing the MIME/extension of that file and i want to open that file in iPad.

So i want to convert my NSData into a file with default MIME type and should open it.

So is there any option like open with...

Any suggestion or sample would be appreciated.

Thanks in advance..

Was it helpful?

Solution

NSData is just raw data.

So you have two primary options:

  • 1) transfer the type
  • or 2) work with a small set of types you recognize, and programmatically determine the type based on the file formats you receive as input. For example, a pdf's first 4 bytes may be %PDF.

If you are working with a small set of formats, you could likely determine the type of data based on the contents of the data. So you might see some APIs which are able to figure out the type the data represents when it has a handful of supported formats which it can identify… but to determine any data would take a long time to process, and to implement. It would also have a fairly high failure rate, due to all the data types/formats available -- published and unpublished, and data formats which don't necessarily have data sequences which identify them uniquely.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top