element-hq / riot-android

A glossy Matrix collaboration client for Android
Apache License 2.0
1.4k stars 394 forks source link

Wrong MIME type for JPEG files without file extension #3435

Open peter-scholtens opened 4 years ago

peter-scholtens commented 4 years ago

mmexport1583934629353

If the Downloads directory in Android contains the attached picture including a file extension, either .jpg or .jpeg, the created thumbnail will be correctly displayed in Riot. It uses the MIME type JPEG. A small check of (part of) the source shows:

  "content": {
    "info": {
      "mimetype": "image/jpeg",
      "thumbnail_info": {
        "mimetype": "image/jpeg",
      },
    },

However, if the file extension is lost, the automatic detection refer to the wrong MIME type, or at least it becomes invisble and it refers to the MIME type JPG, thus without E.

  "content": {
    "info": {
      "mimetype": "image/jpg",
      "thumbnail_info": {
        "mimetype": "image/jpeg",
      },
    },

Logging the data which passes the triple OR function at line 239 in the file VectorRoomMediasSender.java indeed reveals both cases appear:

if (mimeType.startsWith("image/")
        && (ResourceUtils.MIME_TYPE_JPEG.equals(mimeType)
        || ResourceUtils.MIME_TYPE_JPG.equals(mimeType)
        || ResourceUtils.MIME_TYPE_IMAGE_ALL.equals(mimeType))) {
        sendJpegImage(sharedDataItem, resource);
} else {

As far as I understand there is no functional difference between both types. So would it not be handier to set mimeType to JPEG when JPG is detected? Either here, or in the matrix-android-sdk which apparently can output both types, see the function getMimeType() in RoomMediaMessage.java on the matrix-android-sdk. Any advice would be appreciated.

peter-scholtens commented 4 years ago

Repeating the upload using RiotX already fails at uploading the file with comment "Upload request missing 'Content-Type'". Test with RiotX version 0.17.0 downloaded from F-Droid.

peter-scholtens commented 4 years ago

With version 0.18.0 of RiotX, the bug is removed. See https://github.com/vector-im/riotX-android/issues/1075 It still exist in riot-web version 1.5.13.