gpt4 book ai didi

iphone - 如何在 objective-c 中读取 MIME 类型的文件

转载 作者:太空狗 更新时间:2023-10-30 03:09:04 30 4
gpt4 key购买 nike

我有兴趣检测我的 iPhone 应用程序文档目录中文件的 MIME 类型。通过文档搜索没有提供任何答案。

最佳答案

有点hacky,但应该可以,不确定,因为我只是在猜测

有两种选择:

  1. 如果您只需要 MIME 类型,请使用 timeoutInterval: NSURLRequest。
  2. 如果你也想要数据,你应该使用注释掉的 NSURLRequest。

确保在线程中执行请求,因为它是同步的。

NSString* filePath = [[NSBundle mainBundle] pathForResource:@"imagename" ofType:@"jpg"];
NSString* fullPath = [filePath stringByExpandingTildeInPath];
NSURL* fileUrl = [NSURL fileURLWithPath:fullPath];
//NSURLRequest* fileUrlRequest = [[NSURLRequest alloc] initWithURL:fileUrl];
NSURLRequest* fileUrlRequest = [[NSURLRequest alloc] initWithURL:fileUrl cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:.1];

NSError* error = nil;
NSURLResponse* response = nil;
NSData* fileData = [NSURLConnection sendSynchronousRequest:fileUrlRequest returningResponse:&response error:&error];

fileData; // Ignore this if you're using the timeoutInterval
// request, since the data will be truncated.

NSString* mimeType = [response MIMEType];

[fileUrlRequest release];

关于iphone - 如何在 objective-c 中读取 MIME 类型的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1363813/

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