gpt4 book ai didi

ios - 如何在 IOS 中获取不基于扩展名的 Mime 类型

转载 作者:技术小花猫 更新时间:2023-10-29 10:43:20 27 4
gpt4 key购买 nike

我们知道我们可以从文件的扩展名中得到文件的 MIME 类型,但它不完全是。例如,我们改变了文件的扩展名,我们将得到错误的 MIME 类型。我们还知道在 C# 中通过文件签名获取 mime 类型的方法(使用 urlmon.dll Using .NET, how can you find the mime type of a file based on the file signature not the extension ,我的问题是无论文件扩展名如何更改,我们如何才能在 IOS 中获取准确的 mime 类型通过某人,我们可以获得正确的 mime 类型。

感谢您的关注~!

最佳答案

Would you tell me how I get the right mime type exactly when I get a path of a file.

iOS 使用 Uniform Type Identifiers 的概念(UTI) 来处理文档类型。

NSString *path; // contains the file path

// Get the UTI from the file's extension:

CFStringRef pathExtension = (__bridge_retained CFStringRef)[path pathExtension];
CFStringRef type = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, pathExtension, NULL);
CFRelease(pathExtension);

// The UTI can be converted to a mime type:

NSString *mimeType = (__bridge_transfer NSString *)UTTypeCopyPreferredTagWithClass(type, kUTTagClassMIMEType);
if (type != NULL)
CFRelease(type);

您应该考虑直接将 UTI 用于您的目的,而不是将它们转换为功能较弱的 mime 类型。

关于ios - 如何在 IOS 中获取不基于扩展名的 Mime 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9801106/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com