Talk:Using the File API in Moodle forms

Revision as of 06:34, 15 April 2011 by Silverio Armani (talk | contribs) (Let user choose whether external resource should be copied or not)

Jump to: navigation, search

The two code examples in the middle of the document seem a bit random. Some explanation of what's going on in them would be really useful --Howard Miller 08:32, 7 December 2010 (UTC)

Let user choose whether external resource should be copied or not

File picker automatically copies the file from the external repository into Moodle's draft area by calling getFile(UUID) on the repository plug-in.

That partially defeats the point of storing data remotely specially if the external repository version controls its content like HarvestRoad Hive(tm).

From HarvestRoad Hive customer's point of view, they would rather have their content always stored in Hive, not in Moodle, as it happens with Hive-Moodle 1.9 plug-in. So when the content gets updated in Hive, Moodle users will see the updated content. Furthermore, not sync/cron job is required.

However the file picker behaves differently when launched in the "Add Resource > URL" screen, in which the file picker calls getUrl(UUID) on the repository plug-in instead, which is pretty much what Hive customers would like to do.

Proposed solutions:

1) Quick: Rather than always copying the file why don't give a choice on the file picker on whether to copy the resource or create an URL to the resource? You could have two radio button under "Choose licence" on the file picker screen perhaps. This solution might not work if the repository does not support direct URL access or requires authentication.

2) More elaborated: give a choice on the file picker on whether to copy it or create a reference. The reference is the UUID returned by the filepicker. Don't call getFile(UUID) if user has chosen to keep it as a reference. If user has chosen 'reference' then getFile(UUID) has to be invoked everytime the item is viewed. If the item retrieval requires authentication then it is the repository plugin will perform the authentication implicitly.

We at HarvestRoad have successfully implemented solution number 2 however the resource has to be added as an URL which is very limiting. In our solution our getUrl(UUID) creates an URL which actually points back to our Moodle repository plug-in which in turn streams the file from Hive. That is how we solved the authentication issue.


In the above URL we have

* => moodle server
* /repository/hive => Hive repository plug-in
* /view.php => Hive repository plug-in It streams the content from Hive and then re-streams it back to the client. Authentication is performed implicitly if required.
* /5/50/812 => Hive proprietary UUID
* /peugeot.jpg => just a filename

Bear in mind that Moodle itself should be agnostic about the UUID. The UUID is given by the getListing() method in the repository plug-in and it just need to be passed back to getURL(UUID) or getFile(UUID)

I could summarise saying that Moodle should consider storing the UUID of the picked resource rather than downloading the resouce per se. The UUID is then used at request time in order to stream the resource via getFile or to create an Url to it via getUrl.