broken media files

broken media files

by JM Casas -
Number of replies: 6

I use moodle 2.7 and moodle 2.6 in various sites.

I have read other posts addressing this issue before, but it think it has never been resolved.

I use the TinyMCE HTML editor or Atto HTML editor to add images to pages. Images labels look like:

<img src="[my site URL]/draftfile.php?file=/5/user/draft/82886760/img_3_6.png" width="300" height="231" />

I often need to edit the HTML code of pages I create inside courses in order to add some labels to improve style. I paste back the edited code using the HTML editor. 

I view the page content before I save the changes and I can see the images without any problem. But when the saved page is displayed, images don't display properly. When I check the code, links to images have changed:

<img src="[my site URL]/brokenfile.php#?file=/5/user/draft/82886760/img_3_6.png" width="300" height="231" />

If I correct the changes I can see the images again in the editor window, but once saved the changes, images dissapear.

The only thing I can do is to upload images via FTP to a folder inside the moodle folder and link those images from the page, but then those images are available by web to users not logged.

I suppose there are more users affected by this bug

Average of ratings: -
In reply to JM Casas

Re: broken media files

by Justin Hunt -
Picture of Particularly helpful Moodlers Picture of Plugin developers

If it is a bug, it is probably specific to the moodle activity type that you are seeing it in.

In which mod is this occurring (eg forum or page resource) ? It sounds like it is happening in the Page resource. 

Can you give a specific sequence of steps that reliably reproduces the problem? That would be very helpful in honing in on it. Or if you can take a quick screencast of it, that would be good too.


In reply to Justin Hunt

Re: broken media files

by JM Casas -

Hi Justin! Thanks for your quick answer.

First, I have to say that I've spent some weeks searching for a solution to this problem and, surprisingly, shortly after I've posted it, I think I've found it.

The issue occurs in page resource, but also in every activity that allows to include images or videos to be displayed. I use Komodo (for Mac) or Note Pad ++ (for Windows) for editting the html code, because I feel more confortable with then than with moodle HTML editors. I copy the code from Moodle editor, edit it with any of those programs and then I paste the code in Moodle text editor. I don't change anything in the images or videos URLs, but when I save the changes it occurs what I previously described.

Now I've realized that the final URL of images or videos is not the one that is shown in text editor: when you check the source code of the page finaly delivered to the browser, urls are like:

[my site URL]/pluginfile.php?file=/52/mod_page/content/13/img_3_6.png

and not:

[my site URL]/draftfile.php?file=/5/user/draft/82886760/img_3_6.png

If I use the URL displayed in the source code (the first one) everything works OK. It seems that the one that includes draftfile.php (the second one) is a temporary url and should not be used when editing the html code.

I've checked also that images or videos are not accesible in that url unless you are logged in, so this is better than to link this images to a folder in the moodle directory via FTP.

Thank you. I hope this helps.

Average of ratings: Useful (1)
In reply to JM Casas

Re: broken media files

by Justin Hunt -
Picture of Particularly helpful Moodlers Picture of Plugin developers

Well if it is solved, its solved. Thats good. 

But I am not sure if all is well. If all you are doing is editing the styles around the images, I think nothing should break. 

The draft files area is the working area for the editor, and Moodle copies files out of there into permanent storage, and updates the links in the area accordingly. Using the pluginfile.php link directly in the editor, might work. But it would not if the image had just been uploaded and the page housing the editor not yet saved. 

I think somewhere in your process you are changing the source code in such a way that Moodle can't follow the draft file link. 

In reply to Justin Hunt

Re: broken media files

by JM Casas -

I insert an image in the page. I get the following code in the editor:

<p><img src="[site URL]/draftfile.php?file=/5/user/draft/878383659/img_4_5.jpg" alt="" width="300" height="240" role="presentation" style="vertical-align:text-bottom; margin: 0 .5em;" class="img-responsive"><br></p>

I save the page and the image displays fine.

Then I edit the page: I copy the code from the editor and paste it in Note Pad ++. I just add a div tag:

<p><img src="[site URL]/draftfile.php?file=/5/user/draft/878383659/img_4_5.jpg" alt="" width="300" height="240" role="presentation" style="vertical-align:text-bottom; margin: 0 .5em;" class="img-responsive"><br></p>

<div></div>

I copy this code and I paste it in moodle editor. I save the page and the image does not display (just a square with an icon that tells me the image doesn't exist). I check the code in moodle editor:

<p><img src="[site URL]/brokenfile.php#?file=/5/user/draft/878383659/img_4_5.jpg" alt="" width="300" height="240" role="presentation" style="vertical-align:text-bottom; margin: 0 .5em;" class="img-responsive"><br></p>

<div></div

Any suggestion?

In reply to JM Casas

Re: broken media files

by James Ballard -

You cannot copy and paste draft files across different instances of the editor, even in the same place on the site. 

So the first time you open the editor you have instance 878383659, which you can see in the file URL. It seems you have saved this instance to Notepad.

When you re-edit the content a new instance will be generated and so your second copy and paste should have had a different draftfile to the first. You have copied the URL from the 1st instance into the 2nd instance and so the image becomes broken.

If you're editing outside of the editor you need to copy the code fresh every time, otherwise you end up with a broken file.

See MDL-45170 for a potential fix to the copying between editors

 

 


Average of ratings: Useful (1)
In reply to James Ballard

Re: broken media files

by Ajay Kumar -

Hi,

I added one video from admin panel (using tiny mice editor ) but in admin panel link is displaying well. 

But in front end the URL is coming like brokenfile.php example:

<video width="100%" preload="metadata" id="yui_3_17_2_2_1449659988646_81"><source type="video/mp4" src="hostname/brokenfile.php#/5/user/draft/150451661/Home%20Page-Friction-Block%20on%20Inclined%20Plane-1.mp4"></source> </video>


Please Help ?