ios HTTP 请求的 ZIP 文件内容类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20100445/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ZIP file content type for HTTP request
提问by user2960510
I am sending a zip file to server via HTTPREQUEST. What should be the Content-Type
HTTP header valuefor this kind of file?
我正在通过 HTTPREQUEST 向服务器发送一个 zip 文件。这种文件的Content-Type
HTTP 标头值应该是多少?
The file is a ZIP archive that contains images on type PNG.
该文件是一个 ZIP 档案,其中包含 PNG 类型的图像。
Thanks
谢谢
回答by flashdisk
.zip application/zip, application/octet-stream
回答by Krumelur
The standard MIME type for ZIP files is application/zip
. The types for the files inside the ZIP does not matter for the MIME type.
ZIP 文件的标准 MIME 类型是application/zip
. ZIP 中文件的类型与 MIME 类型无关。
As always, it ultimately depends on your server setup.
与往常一样,它最终取决于您的服务器设置。
回答by Mundi
[request setValue:@"application/zip" forHTTPHeaderField:@"Content-Type"];
回答by Rob
If you want the MIME type for a file, you can use the following code:
如果需要文件的 MIME 类型,可以使用以下代码:
- (NSString *)mimeTypeForPath:(NSString *)path
{
// get a mime type for an extension using MobileCoreServices.framework
CFStringRef extension = (__bridge CFStringRef)[path pathExtension];
CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, extension, NULL);
assert(UTI != NULL);
NSString *mimetype = CFBridgingRelease(UTTypeCopyPreferredTagWithClass(UTI, kUTTagClassMIMEType));
assert(mimetype != NULL);
CFRelease(UTI);
return mimetype;
}
In the case of a ZIP file, this will return application/zip
.
对于 ZIP 文件,这将返回application/zip
.