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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 22:27:39  来源:igfitidea点击:

ZIP file content type for HTTP request

ioshttpnsurlrequest

提问by user2960510

I am sending a zip file to server via HTTPREQUEST. What should be the Content-TypeHTTP header valuefor this kind of file?

我正在通过 HTTPREQUEST 向服务器发送一个 zip 文件。这种文件的Content-TypeHTTP 标头应该是多少?

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.