Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-42616

Files: Support custom file types

XMLWordPrintable

    • Icon: New Feature New Feature
    • Resolution: Fixed
    • Icon: Major Major
    • 2.9
    • 2.4.3, 2.9
    • Libraries
    • MOODLE_24_STABLE, MOODLE_29_STABLE
    • MOODLE_29_STABLE
    • MDL-42616-master
    • Hide

      NOTE: There are Behat tests covering the editing interface (add/update/delete and view), this test script is just a summary.

      I have written the test script in 3 sections. If the UI is included, I suggest sections A then C. If the UI is not included then do sections B and C.

      A Configure a custom file type (using UI):
      1. Log in as admin and go to Site administration -> Server -> File types
      2. Click the ‘Add’ button to add a new custom file type
      3. On the ‘Add a new custom file type’ screen, set extension as ‘mobi’, MIME type as ‘application/x-mobipocket-ebook’, description type as custom and the custom description as ‘Kindle ebook’. For File icon, choose ‘document’.
      4. Click ‘Save changes’. The page will redirect to the custom file type listing page. You should see that mobi file type will now be listed.

      B Configure a custom file type (using config.php):
      1. Add the following code to config.php:

      $CFG->customfiletypes = array(
          (object)array(
              'extension' => 'mobi',
              'icon' => 'document',
              'type' => 'application/x-mobipocket-ebook',
              'customdescription' => 'Kindle ebook'
          )
      );
      

      C Test the display of your added custom file type:
      1. Add a file activity to your testing course
      2. In the editing screen , fill in the name and description fields with any text you like.
      3. Upload a file called test.mobi (you don't need to find a genuine mobi file, just rename any normal text file to test.mobi then upload it).
      4. Expand ‘Appearance’ section and tick the ‘Show type’ box. You can leave other settings here as default.
      5. Click ‘Save and return to course’ and you should see your new created file activity.
      EXPECTED: After the activity name, you should see ‘Kindle ebook’ as file type description. The icon should be the standard Moodle document icon.

      Show
      NOTE: There are Behat tests covering the editing interface (add/update/delete and view), this test script is just a summary. I have written the test script in 3 sections. If the UI is included, I suggest sections A then C. If the UI is not included then do sections B and C. A Configure a custom file type (using UI): 1. Log in as admin and go to Site administration -> Server -> File types 2. Click the ‘Add’ button to add a new custom file type 3. On the ‘Add a new custom file type’ screen, set extension as ‘mobi’, MIME type as ‘application/x-mobipocket-ebook’, description type as custom and the custom description as ‘Kindle ebook’. For File icon, choose ‘document’. 4. Click ‘Save changes’. The page will redirect to the custom file type listing page. You should see that mobi file type will now be listed. B Configure a custom file type (using config.php): 1. Add the following code to config.php: $CFG->customfiletypes = array( (object)array( 'extension' => 'mobi', 'icon' => 'document', 'type' => 'application/x-mobipocket-ebook', 'customdescription' => 'Kindle ebook' ) ); C Test the display of your added custom file type: 1. Add a file activity to your testing course 2. In the editing screen , fill in the name and description fields with any text you like. 3. Upload a file called test.mobi (you don't need to find a genuine mobi file, just rename any normal text file to test.mobi then upload it). 4. Expand ‘Appearance’ section and tick the ‘Show type’ box. You can leave other settings here as default. 5. Click ‘Save and return to course’ and you should see your new created file activity. EXPECTED: After the activity name, you should see ‘Kindle ebook’ as file type description. The icon should be the standard Moodle document icon.
    • BACKEND Sprint 19
    • Medium

      Updated This issue now refers to a custom tool that lets administrators add new file types. You can define the MIME type and text description, and select an icon from the existing Moodle file type icon set.

      The below is the original description from the problem we were experiencing (when it misdiagnosed a file as a zip file):

      A fairly frequent occurrence is that certain courses will use files of a specific, obscure format intended for a particular software program. Often these formats are based on standard formats. Students are expected to download the files (and the software, either free software or commercial software that's been licensed for them) and then open the files in the software.

      Moodle makes this difficult because it automatically identifies generic file types, incorrectly. The worst offender is zip. I'm not sure if it also does the same for XML.

      This then causes problems for students because when they download the files, depending on the browser (a) they may get renamed to the zip extension, and (b) it also offers to open them in an unzip program. Both these things cause problems for students, who are generally not technically skilled. Even if renaming a file isn't a challenge, we still have to tell them to do it, and they're going to be asking the obvious question, why on earth are you making us download files with the wrong name and then renaming them...

      Here is an example of the type of issue request I get:

      <<
      The three GeoGebra files on this page [...] are displayed as .zip files when they should be .ggb files. When I downloaded the files they saved as .ggb files, but when Zoe tried this they saved as .zip files that couldn't be used.

      The files are displaying correctly on the 12J presentation website [...]. Has something changed in the VLE updates that now causes the files to be associated with Winzip?

      This is pretty urgent as the students need to use these files now.
      >>

      I don't think we should add a complete list of obscure random MIME types and icons (GeoGebra? Come on) to Moodle core. However, Moodle really needs to stop breaking these file downloads.

      I can do temp fix for this kind of problems by running a database query like the following:

      <<
      update mdl_files set mimetype='document/unknown' where filename like '%.ggb' and mimetype != 'document/unknown'
      >>

      But obviously I have to do that each time this is reported and if they upload any more files they will be screwed again. And it will only ever be reported when students are actually due to be using the files at that moment, so it always turns into an urgent request...

      To be honest I'm not sure what the right solution is here, but I can see two good possibilities:

      1. Stop the auto-detection logic for common container formats (.zip, .xml), so that only files called .zip get the zip mimetype and others get a suitable unknown type mimetype.

      or

      2. Make it easy to add user-configured MIME types in the admin user interface (this is roughly MDL-7101 - yay four-digit issue). Since I'd like this to happen in stable branches, I suggest this could be a minimal implementation using a single text area where you enter a list of types in a basic text format, similar to mime.types but also including the format description and which icon to use.

      I am very happy to work on this, with the proviso that I'd like to do a minimal implementation which is easy to implement and backport rather than a fancy GUI - fancy GUI could be left for later work if required.

      Before I do anything, could I get opinions on this - what's the best approach? To me it sounds like adding the mime configuration would be better but...

            quen Sam Marshall
            quen Sam Marshall
            Frédéric Massart Frédéric Massart
            Dan Poltawski Dan Poltawski
            Zachary Durber Zachary Durber
            Votes:
            4 Vote for this issue
            Watchers:
            15 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.