About 7-Zip archive files
7-Zip’s format usually compresses better than ZIP, but neither Windows Explorer (before Windows 11’s 2023 updates) nor macOS Finder could open it out of the box. For files meant for anyone, ZIP is the safer choice.
File signature
7Z files start with 37 7A BC AF 27 1C ("7z\xBC\xAF\x27\x1C"). The extension and the type a browser reports for an upload both
come from the file name, so check these bytes on the server before trusting a file.
Serve .7z with the right Content-Type
Content-Type: application/x-7z-compressed
application/x-7z-compressed 7z;
AddType application/x-7z-compressed .7z
@7z path *.7z
header @7z Content-Type "application/x-7z-compressed"
curl -sI https://example.com/file.7z | grep -i '^content-type'
# Content-Type: application/x-7z-compressed
Set the type in code
res.set('Content-Type', 'application/x-7z-compressed');
// Or make the browser download it:
res.attachment('file.7z');
import mimetypes
mimetypes.add_type('application/x-7z-compressed', '.7z') # if your system doesn't know it
mimetypes.guess_type('file.7z')[0] # 'application/x-7z-compressed'
mime.AddExtensionType(".7z", "application/x-7z-compressed")
w.Header().Set("Content-Type", "application/x-7z-compressed")
Accept .7z uploads
<input type="file" accept=".7z,application/x-7z-compressed">
The accept attribute only filters the file picker; users can still choose another file. Listing the
extension as well as the type matters, because operating systems don’t always report the type you expect.
Related types
-
.zip (
application/zip): ZIP archive -
.rar (
application/vnd.rar): RAR archive -
.gz (
application/gzip): Gzip file
More archives
.tar . Look up any extension or type with the MIME type lookup.
Sources
Spotted a mistake? Email hello@devtoolsmith.com and we’ll fix it.
Frequently asked questions
What is the MIME type for .7z files?
application/x-7z-compressed. The full header is "Content-Type: application/x-7z-compressed".
Why does my server send the wrong Content-Type for .7z?
Web servers pick the type from the file extension using a table (mime.types in nginx and Apache). If .7z is missing from that table, they send a default such as application/octet-stream or text/plain. Add the mapping as shown on this page, then check the response with "curl -sI".
How can I check that a file really is 7Z?
Look at the first bytes rather than the extension or the type the browser reports, which both come from the file name. 7Z files start with 37 7A BC AF 27 1C ("7z\xBC\xAF\x27\x1C"). The MIME type lookup on this site reads them for you when you drop a file on it.