matrix-org / matrix-js-sdk

Matrix Client-Server SDK for JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Empty Content-Type when uploading file without suffix

JakubOnderka opened this issue · comments

If you try to upload file without suffix, empty Content-Type header is send by Element client. Empty Content-Type can be blocked by some web application filters.

The reason is this line:

const contentType = opts.type ?? (file as File).type ?? "application/octet-stream";

It expects that if file content type is unknown, default MIME type application/octet-stream should be send. But according to specification, for unknown file, File.type is empty string (see https://developer.mozilla.org/en-US/docs/Web/API/Blob/type). And ?? operator consider empty string as valid value.

So instead ?? operator, || should be used.