Swift中的路径扩展和MIME类型的文件类型
我正在学习Swift,并用一个单元格制作了一个表格,并按MIME类型(使用路径扩展)分组分类。 我对扩展有一个疑问。 如果图像(例如,它可能是视频或PDF)是从Internet中获取的,那么我不确定它们是否具有扩展名 如何在不使用路径扩展的情况下在文件系统内获取文件的模拟类型? PS:对不起,我的英语不好,这不是我的母语
I'm learning swift , and I made a table with cells that show an image ,and classes in groups by MIME TYPE (using path extension).
I had a question about extensions.
If the images (for example, it could be a video or a pdf) are taken from internet , i'm not sure if they have the extension or not
how can I get the MIMEtype of a file inside my file System without using path extension ?
PS :Sorry for my bad english it's not my native language
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
如果有人想从文件的实际URL中获取模拟型,则该代码对我有用:
If anyone wants to get the MimeType from the actual URL of the file this code worked for me:
iOS 14.0 +
使用iOS下方的扩展
14
mimeType.swift
如何使用
与 nsurl 一起使用, url , nsString , string
参考2
iOS 14.0 +
Use the extensions
Below iOS 14
MimeType.swift
How to use
Workes with NSURL, URL, NSString, String
Reference 1
Reference 2
如果您需要检查URL包含一些图像或音频文件或视频文件,则这里是Swift 5.1代码:
If you need to check URL contains some Image or Audio file or Video file, here is Swift 5.1 code:
Swift 5.5 iOS 14.0+
Swift 5.5 iOS 14.0+
要从UTI获取扩展名,这是 swift 4.1 代码:
mov
forcom.apple.quicktime-movie
To fetch an extension from UTI, here is Swift 4.1 code:
mov
forcom.apple.quicktime-movie
ios15 @dmih的解决方案看起来像这样:
iOS15 compatible version of @Dmih's solution looks like this:
保罗·莱恩(Paul Lehn :
iOS 14+
Answer that provided by Paul Lehn(most liked answer) didn't work for me, because I'm developing for iOS 16 at this moment, due to deprecation of methods that was used in his solution, I decided to refactor the code a bit:
iOS 14+
假设您将数据接收为NSDATA,请遵循此帖子:
例如,在Swift中:
Assuming you are receiving your data as NSData, follow this Post: https://stackoverflow.com/a/5042365/2798777
In Swift for example:
iOS 15
iOS 15