41

I'm just designing the schema for a database table which will hold details of email attachments - their size in bytes, filename and content-type (i.e. "image/jpg", "audio/mp3", etc).

Does anybody know the maximum length that I can expect a content-type to be?

3 Answers 3

49

I hope I havn't misread, but it looks like the length is max 127/127 or 255 total.

RFC 4288 has a reference in 4.2 (page 6):

Type and subtype names MUST conform to the following ABNF:

   type-name = reg-name
   subtype-name = reg-name

   reg-name = 1*127reg-name-chars
   reg-name-chars = ALPHA / DIGIT / "!" /
                   "#" / "$" / "&" / "." /
                   "+" / "-" / "^" / "_"

It is not clear to me if the +suffix can add past the 127, but it appears not.

3
  • 1
    I'd be glad if @ian-nelson (or @speaker) could emphasize number 255 in this answer. Feb 18, 2013 at 14:37
  • 2
    @ŁukaszSiwiński like that?
    – Ian Nelson
    Feb 18, 2013 at 15:44
  • 1
    @lankymart it is now.
    – Ian Nelson
    Mar 14, 2014 at 9:07
8

In RFC 6838 which is latest standard and obsoletes RFC4288, there is a following statement.

"Also note that while this syntax allows names of up to 127 characters, implementation limits may make such long names problematic. For this reason, <type-name> and <subtype-name> SHOULD be limited to 64 characters."

64+1+64 = 129.

But I suspect the standard should mean 63+1+63=127.

link: https://www.rfc-editor.org/rfc/rfc6838#section-4.2

1
  • Would be handy to link to the RFC pages. May 10, 2016 at 13:45
2

We run an SaaS system that allows users to upload files. We'd originally designed it to store MIME Types up to 50 characters. In the last several days we've seen several attempts to upload 71-bytes types. So, we're changing to 250. 100 seemed "good" but it's only a few more than the max we're seeing now. 500 seems silly, so 250 is the selected one.

2
  • What kind of files have that length?
    – Pithikos
    Apr 28, 2020 at 10:33
  • 3
    "application/vnd.openxmlformats-officedocument.wordprocessingml.document" Apr 29, 2020 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.