ZIP file content type for HTTP request

IosHttpNsurlrequest

Ios Problem Overview


I am sending a zip file to server via HTTPREQUEST. What should be the Content-Type HTTP header value for this kind of file?

The file is a ZIP archive that contains images on type PNG.

Thanks

Ios Solutions


Solution 1 - Ios

.zip    application/zip, application/octet-stream

Solution 2 - Ios

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.

As always, it ultimately depends on your server setup.

Solution 3 - Ios

[request setValue:@"application/zip" forHTTPHeaderField:@"Content-Type"];

Solution 4 - Ios

If you want the MIME type for a file, you can use the following code:

- (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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser2960510View Question on Stackoverflow
Solution 1 - IosflashdiskView Answer on Stackoverflow
Solution 2 - IosKrumelurView Answer on Stackoverflow
Solution 3 - IosMundiView Answer on Stackoverflow
Solution 4 - IosRobView Answer on Stackoverflow