Skip to main content

Content-Type for attachments uploaded via the API

Which Content-Type to specify for an attachment and what the server will reject

Written by Petr Pech

An attachment uploaded via the API is accompanied by a Content-Type header, which specifies the file type. The server enforces two conditions on its content — and the earlier 50-character limit no longer applies, so long Office format types can now be given in full.


Rules for the value

Rule

What happens if it's not met

The value must be in the form typ/podtyp, i.e. it must contain a slash.

A value without a slash results in a 500 error, and the attachment is not saved.

The value may be at most 127 characters long.

From 128 characters onward, the request fails with a 500 error (a database-related error).

The header does not need to be specified.

The attachment is saved with the type content/unknown.

The stored value is returned in the Content-Type header when you download the attachment via the /prilohy/{ID}/content address — so it's important that it's filled in correctly, to ensure the file opens in the right application.


Types for office formats

Standard Office file types easily fit within the 127-character limit (the longest one has 73 characters):

File

Content-Type

.docx

application/vnd.openxmlformats-officedocument.wordprocessingml.document

.dotx

application/vnd.openxmlformats-officedocument.wordprocessingml.template

.xlsx

application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

.xltx

application/vnd.openxmlformats-officedocument.spreadsheetml.template

.pptx

application/vnd.openxmlformats-officedocument.presentationml.presentation

.ppsx

application/vnd.openxmlformats-officedocument.presentationml.slideshow

.potx

application/vnd.openxmlformats-officedocument.presentationml.template

.pdf

application/pdf

🚨 Shortened forms such as vnd.ms-word.document.macroEnabled.12, which used to be recommended as a workaround for the 50-character limit, now result in a 500 error — they're missing the slash. Moreover, they denote a different format (files with macros). Therefore, use the full form with the application/ prefix; if you need the type for a macro-enabled format, it's application/vnd.ms-word.document.macroEnabled.12.


Related

Did this answer your question?