How do I retrieve plugin files where default is set to download

How do I retrieve plugin files where default is set to download

by Will Nahmens -
Number of replies: 0

I am building a small plugin that runs a bit of javascript that will run on top of the database activity (mod_data), which will take a file that has been uploaded by a user, and if the file is an image or pdf, create a modal window that shows a preview of the image or pdf to be downloaded. Currently the database activity provides an "a" element which when clicked, downloads the file. From my understanding of the File API documentation, each plugin determines it's own way to serve files using the function MYPLUGIN_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array())  hook, and in the case of the database activity, any url that uses it's pluginfile.php function to serve the resource will force download

What I need to do is get a url that will point to that file, and then set it as the source of an "<img>" element or an "<embed>" element (for PDF). I've tried using the webservice to retrieve this file at the endpoint "

/webservice/pluginfile.php/54/mod_data/content/6/Annex%201%20TOM%20Hetzner.pdf?token=mytoken"
for this file, but that also only returns the file itself or initiates a download if the url is visited, but the url can't be used to show the image. 

How can I find a url that will allow me to show the image that has been uploaded to the activity, while avoiding the mod_data standard behavior of forcing download? Is there a way I can pass a forcedownload=false parameter with my webservice request? Or is there some way for me to reconstruct the url with the existing parameters that will give me a url that will reference the image? 

Many thanks for any help! 

Average of ratings: -