** Changed in: mahara/1.2
       Status: Fix Committed => Fix Released

-- 
Mime-type recognition fails for file uploads when Mahara behind reverse proxy
https://bugs.launchpad.net/bugs/591373
You received this bug notification because you are a member of Mahara
Contributors, which is subscribed to Mahara.

Status in Mahara ePortfolio: Fix Committed
Status in Mahara 1.2 series: Fix Released

Bug description:
When Mahara is hosted behind a reverse proxy, files uploaded are not recognized 
as their proper types. For example: if I go to "My Portfolio" and "My Files" to 
upload an gzip file, the file will upload properly but will not be properly 
recognized as being an archive. The result is that the generic file icon is 
used and the "Unzip" link is not displayed.

After looking at the code, I can see that Mahara is depending on the browser to 
send the proper mime-type when the file is uploaded. In our case, this value is 
being set to a generic value (application/octet-stream) when passed through our 
reverse proxy. The code that is responsible for handling new archive files 
(from archive/file/lib.php) is here:

    public static function new_archive($path, $data) {
        if (!isset($data->filetype)) {
            return self::archive_from_file($path, $data);
        }
        $descriptions = self::archive_file_descriptions();
        $validtypes = self::archive_mime_types();
        if (isset($validtypes[$data->filetype])) {
            return self::archive_from_file($path, $data, 
$descriptions[$validtypes[$data->filetype]->description]);
        }
        return false;
    }

This code checks for a mime-type first (sent by the browser) and if it finds 
one, assumes that it is correct. Perhaps it would be better if the code tried 
to determine the mime-type using the file extension in the case where the 
browser sends "application/octet-stream". Like this:

    public static function new_archive($path, $data) {
        if (!isset($data->filetype)) {
            return self::archive_from_file($path, $data);
        }
        if ($data->filetype == "application/octet-stream" &&
            $result = self::archive_from_file($path, $data)) {
            return $result;
        }
        $descriptions = self::archive_file_descriptions();
        $validtypes = self::archive_mime_types();
        if (isset($validtypes[$data->filetype])) {
            return self::archive_from_file($path, $data, 
$descriptions[$validtypes[$data->filetype]->description]);
        }
        return false;
    }

When I make this change, everything works properly for me.



_______________________________________________
Mailing list: https://launchpad.net/~mahara-contributors
Post to     : mahara-contributors@lists.launchpad.net
Unsubscribe : https://launchpad.net/~mahara-contributors
More help   : https://help.launchpad.net/ListHelp

Reply via email to