相关疑难解决方法(0)

使用.NET,如何根据文件签名而不是扩展名找到文件的mime类型

我正在寻找一种简单的方法来获取文件扩展名不正确或没有给出的mime类型,类似于.Net中的这个问题.

c# mime mime-types

234
推荐指数
9
解决办法
21万
查看次数

如何在Swift中的路径中找到文件UTI for file,withouth pathExtension

我一直试图转换这个代码,我从这个例子(在Objective-c中)没有运气.

    String *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);
Run Code Online (Sandbox Code Playgroud)

我的代码是这样的

    import MobileCoreServices
    let path: String?
    let pathExt = path.pathExtension as CFStringRef
    let type = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, pathExtension, NULL);
    let mimeType = UTTypeCopyPreferredTagWithClass(type, kUTTagClassMIMEType)
    if type != Null …
Run Code Online (Sandbox Code Playgroud)

uti ios swift swift2

8
推荐指数
1
解决办法
4105
查看次数

标签 统计

c# ×1

ios ×1

mime ×1

mime-types ×1

swift ×1

swift2 ×1

uti ×1