Hi, I want to read the file type from a downloaded file in iOS which does not have an extension.

Eg: http://somelink/2a3bc

Its a valid pdf file. When I download it gets downloaded as NSData stream at a url(NSURL). if I rename it to 2a3bc.pdf it can be previewed using UIDocumentInteractionController but when I open the url without extension it does not recognise it as file valid file. Its UTI becomes public.data

Is there any way I can read the file type from NSData and rename the file according to that and open it using UIDocumentInteractionController.

Regards, Nandu Ahmed

有帮助吗?

解决方案

Your download task has a link to the NSURLResponse *response that was received as part of the download. This contains the MIMEType that was set for the download. You should use that to determine what the file type is.

Technically you could read the first few bytes of data in the downloaded file but you would need a good amount of code to compare and identify all of the byte sequences...

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top