Question imports with images

Question imports with images

by Thomas College -
Number of replies: 12

I was hoping to get a definite answer on importing questions with images if possible.  The Moodle Doc here: https://docs.moodle.org/28/en/Import_questions#How_do_you_create_XML_files_to_enable_import_of_images.3F gives a method to import questions with images, but from what I can tell, the VLEtools converter mentioned in the Doc requires a 15 Euro registration fee.

After reading the forum thread here: https://moodle.org/mod/forum/discuss.php?d=171500 it would seem that one should be able to export and import questions with images using the XML format.  I've tested using the XML format, but have not been able to successfully import images that are included in questions.

Should one be able to include images with imported questions?  Is there a specific procedure that is needed in order to accomplish this?  We are currently running Moodle version 2.8.3.

Thanks

Average of ratings: -
In reply to Thomas College

Re: Question imports with images

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Yes, Moodle XML files can contain images. To see how, create a question in Moodle containing images, and export it.

The easiest way to see the required format may be to look at the export code: https://github.com/moodle/moodle/blob/master/question/format/xml/format.php#L1088. Basically, in the HTML you have the image encoded in base-64.

In reply to Tim Hunt

Re: Question imports with images

by Thomas College -

Tim, thanks for the reply.  I've reviewed the export code as you suggested and was able to successfully export and then import a question containing an image between two test courses.

For the export/import tests I had done previously, I used an export from one of our instructor's courses .  When I imported the questions, images no longer displayed properly in the questions.  The questions had a place holder for the image, but all that was displayed was a small X followed by the file's name. 

Are there any typical reasons as to why images fail to import with questions, or does anyone have any suggestions for things to check that might narrow down the cause?

Thanks

In reply to Thomas College

Re: Question imports with images

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I suspect it is a problem with how the images were added to the old questions. They may appear to work, but not be properly associated with the question, and so not be included in the export.

Can you show us the XML you get when you export one such question?

In reply to Tim Hunt

Re: Question imports with images

by Thomas College -

Tim, thanks for the reply.  Below is a small sample of the original XML:

<questiontext format="html">
      <text><![CDATA[<img width="610" height="499" align="bottom" alt="nar002-1.jpg" src="@ @PLUGINFILE@ @/ppg__examview__p3__nar002-1.jpg" border="0">
<br><br>
Question content here.]]></text>
    </questiontext>
    <generalfeedback format="html">
      <text></text>
    </generalfeedback>
  

I compared this content with an XML export made from a sub category in the course's total question bank.  When that export was made, the questions contained base-64 encoding information.  My original export doesn't have any encoding information.  I guess that's why images didn't import.

The course's question bank is rather large (approximately 900 questions).  Would the number of questions have anything to do with the missing encoding information?

Thanks

(Edited by Tim Hunt to top Moodle messing with the @ @PLUGINFILE@ @ bit of the XML - original submission Tuesday, 10 March 2015, 3:38 PM)

In reply to Thomas College

Re: Question imports with images

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

No, it will be something to do with how the image was inserted.

In reply to Marcus Green

Re: Question imports with images

by Thomas College -

Hi Marcus,

Would there be a process for adding images that would cause images to import properly when one of the sub categories is exported but not when the entire course category is exported?

We're currently using TinyMCE for an editor, if it makes a difference.

I'll try to get more details from the instructor on how the images were inserted.

Thanks

In reply to Thomas College

Re: Question imports with images

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

It is a long time since I first looked into this but I have just done a little experimenting. If you put an image in via a URL then it won't get saved within the export it will just save the URL.  In my experience if you paste in an image then it will be saved with the item and so backed up and restored correctly. However some browsers don't allow pasting of images without some fiddling.

Average of ratings: Useful (1)
In reply to Thomas College

Re: Question imports with images

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Can you try editing the qusetion in Moodle? Does the image show up there?

You are right that the image data should be in the XML, base-64 encoded.
In reply to Tim Hunt

Re: Question imports with images

by Thomas College -

Hi, Tim.  The image doesn't show up when I edit the imported question either.

Thanks

In reply to Thomas College

Re: Question imports with images

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Right, so when is the last time the image was working?

In reply to Tim Hunt

Re: Question imports with images

by Thomas College -

Hi Tim, sorry for the late reply. 

When I export and import the entire question bank category, images do not work.  But if I export and import a sub category, images do work properly. 

The entire question bank category does contain a large number of questions (approximately 1800 questions).  Would the large number of questions have anything to do with images not exporting and importing  properly?

Thanks

In reply to Thomas College

Re: Question imports with images

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

If the large number of questions was the problem, it would fail by running out of memory, and you would just get a blank screen. You would not get an XML file with the files data missing.