Images not appearing in my plugin's content in mobile app

Images not appearing in my plugin's content in mobile app

by Iglika Raykova -
Number of replies: 9

Hi folks!

I'm creating a plugin and also support for it for the mobile app. But my mobile app is the old version - 3.4.2 that's why I've put external.php in my classes directory to retrieve the data from the plugin. For my content files I'm using external_util::get_area_files() function but it returns no files.  In the content the images' URLs are returned properly but images are not loaded. When I try to open the image URL it shows me "Sorry, the requested file could not be found" error.

On the website the images displayed properly but for the mobile app I can not understand where is the problem. For the website I've similar problem with the images but created method <myplugin>_pluginfile() and the problem was solved. Should I do something similar with in the external file also or what I should do to get my files/images visible on the mobile app?

Average of ratings: -
In reply to Iglika Raykova

Re: Images not appearing in my plugin's content in mobile app

by Juan Leyva -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Hi,

could you share here the image URLs generated by your plugin?

Thanks, Juan

In reply to Juan Leyva

Re: Images not appearing in my plugin's content in mobile app

by Iglika Raykova -
Hi Juan,
the image URL is the following: https://moodle/webservice/pluginfile.php/1/mod_myplugin/content/4/image.jpg?token=wstoken&offline=1.
The digit 1 I hard coded because these images are uploaded in the content from the admin area of the plugin and on the front end user can create instances of that content. So in DB images are saved with contextid = 1.

Thanks for the help,
Iglika
In reply to Iglika Raykova

Re: Images not appearing in my plugin's content in mobile app

by Juan Leyva -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Hi,

and what about the URL generated for the website, it should be almost the same. Could you copy it here?

If the image works for web, just replacing pluginfile.php with webservice/pluginfile.php and adding ?token=YOUR_TOKEN must work
In reply to Juan Leyva

Re: Images not appearing in my plugin's content in mobile app

by Iglika Raykova -
Hi again,
the URL generated for the website is: https://moodle/pluginfile.php/1/mod_myplugin/content/4/image.jpg. I've replaced pluginfile.php with webservice/pluginfile.php and added ?token=MY_TOKEN and it works when I open it in browser. So you suggest in my external.php file to generate the links as you described above and to use these links instead of ones that were generated from external_util::get_area_files() method?
In reply to Iglika Raykova

Re: Images not appearing in my plugin's content in mobile app

by Iglika Raykova -
Dear Juan,
in fact the links generated into the mobile app are almost the same as you described. Just one more parameter is added '&offline=1'. So it is very strange that the link works when I open it as address in browser, but not works when it is in the content in the mobile app.
So can you please help me to solve this issue, I'm out of ideas.

Best regards,
Iglika
In reply to Iglika Raykova

Re: Images not appearing in my plugin's content in mobile app

by Juan Leyva -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Hi,
you should enable "Debugging" at Developer level and also the option to "Display errors" in Administration -> Development and then open manually in a browser tab the webservice/pluginfile.php links are not working
I suspect is related to the token being incorrect?
In reply to Juan Leyva

Re: Images not appearing in my plugin's content in mobile app

by Iglika Raykova -
Hi Juan,
I've enabled the "Debugging" mode and the following result returns me when I try access the link though the browser:

error    "Sorry, the requested file could not be found"
errorcode    "filenotfound"
stacktrace    "* line 482 of /lib/setuplib.php: moodle_exception thrown\n* line 1913 of /lib/filelib.php: call to print_error()\n* line 4723 of /lib/filelib.php: call to send_file_not_found()\n* line 63 of /webservice/pluginfile.php: call to file_pluginfile()\n"
debuginfo    "\nError code: filenotfound"
reproductionlink    "https://mymoodle/course/view.php?id=1"

And into the error_log file:

Default exception handler: Sorry, the requested file could not be found Debug:
Error code: filenotfound
* line 482 of /lib/setuplib.php: moodle_exception thrown
* line 1913 of /lib/filelib.php: call to print_error()
* line 4723 of /lib/filelib.php: call to send_file_not_found()
* line 63 of /webservice/pluginfile.php: call to file_pluginfile()


No token is mentioned here. I checked for my mobile user I have token and capability mod/myplugin:view.  However I created another token, restated the app and the token was changed with new one but the result is the same.


In reply to Iglika Raykova

Re: Images not appearing in my plugin's content in mobile app

by Iglika Raykova -
Hi,
I though if I should write some additional methods in my lib.php or external.php classes? I've tried to return the content files using external_util::get_area_files() but with no success for the 'content' filearea files. Then tried to return the 'intro' files with the same method - still no results. Must these files to be present in get_myplugin_content_by_courses_returns function as objects or just in the HTML content as they are links is enough? And why external_util::get_area_files do not return them? Any idea?
In reply to Juan Leyva

Re: Images not appearing in my plugin's content in mobile app

by Iglika Raykova -
Dear Juan,
can you please help me with this. I'm stuck on it for few days and no idea at all how to resolve it. It seems that everything is right but I still have no success result.

Thanks in advance,
Iglika