Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Talk:Using the File API in Moodle forms: Difference between revisions

From MoodleDocs
No edit summary
 
(6 intermediate revisions by one other user not shown)
Line 1: Line 1:
I honestly don't know what this doc is saying in regards of how to use the file api. Should give more details on how to handle the mform file data.


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 --[[User:Howard Miller|Howard Miller]] 08:32, 7 December 2010 (UTC)
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 --[[User:Howard Miller|Howard Miller]] 08:32, 7 December 2010 (UTC)


== Let user choose whether external resource should be copied or not ==
== Choosing whether an external resource should be copied into Moodle or referenced by Moodle ==


File picker automatically copies the file from the external repository into Moodle's draft area by calling getFile(UUID) on the repository plug-in.
With most Add Resource and Add Activity options, the 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).
This can be problematic for customers that require (for copyright or security reasons) that all content reside within the repository.  It is particularly tricky when the remote content is changing through a version control or workflow process as the Moodle copy will be out of sync with the repository original.  These are common requirements for users of 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.
Long term Moodle-Hive customers were familiar with this model from a custom integration HarvestRoad built with Moodle 1.9. When the content is updated in Hive, Moodle users see the updated content. Furthermore, no sync process or 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.
The file picker behaves differently when launched with the "Add Resource > URL" option.  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:
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.
1) Quick: Rather than always copying the file into Moodle, offer a choice in the file picker of copying the resource, or creating an URL to the external location of the resource. You could have two radio buttons 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.
[[File:Ref type.png]]


We at HarvestRoad have successfully implemented solution number 2 however the resource has to be added as an URL is very limiting. In our solution our getUrl(UUID) creates and 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.
2) More elaborate: offer a choice in the file picker of copying the resource, or creating a reference to the external resource. The reference in this case would be the UUID returned by the file picker. If the user chooses to create a reference then the call to getFile(UUID) would be omitted when using the file picker, and is instead invoked every time the item is viewed. If the item retrieval requires authentication then the repository plugin will perform the authentication.
 
The Hive team have partially implemented solution number 2, however the resource has to be added as a URL which is not ideal. 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.


eg: http://hive43demo.harvestroad.com.au/moodle2/repository/hive/view.php/5/50/812/peugeot.jpg
eg: http://hive43demo.harvestroad.com.au/moodle2/repository/hive/view.php/5/50/812/peugeot.jpg
Line 24: Line 27:
In the above URL we have
In the above URL we have


http://hive43demo.harvestroad.com.au/moodle2 => moodle server
* http://hive43demo.harvestroad.com.au/moodle2 => moodle server
/repository/hive => Hive repository plug-in
* /repository/hive => Hive repository plug-in
/view.php => Hive repository plug-in proxy stream. It streams the content from Hive and restream it back to the client.
* /view.php => Hive repository plug-in stream.er 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 property UUID
* /5/50/812 => Hive proprietary UUID
/peugeot.jpg => just a filename
* /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)
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 needs 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.
To summarise, it would be useful if Moodle could store the UUID of the picked resource rather than downloading the resouce per se. The UUID can then be used at request time in order to stream the resource via getFile or to create an Url to it via getUrl.

Latest revision as of 17:52, 4 September 2012

I honestly don't know what this doc is saying in regards of how to use the file api. Should give more details on how to handle the mform file data.

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)

Choosing whether an external resource should be copied into Moodle or referenced by Moodle

With most Add Resource and Add Activity options, the file picker automatically copies the file from the external repository into Moodle's draft area by calling getFile(UUID) on the repository plug-in.

This can be problematic for customers that require (for copyright or security reasons) that all content reside within the repository. It is particularly tricky when the remote content is changing through a version control or workflow process as the Moodle copy will be out of sync with the repository original. These are common requirements for users of HarvestRoad Hive(tm).

Long term Moodle-Hive customers were familiar with this model from a custom integration HarvestRoad built with Moodle 1.9. When the content is updated in Hive, Moodle users see the updated content. Furthermore, no sync process or cron job is required.

The file picker behaves differently when launched with the "Add Resource > URL" option. 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 into Moodle, offer a choice in the file picker of copying the resource, or creating an URL to the external location of the resource. You could have two radio buttons 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.

Ref type.png

2) More elaborate: offer a choice in the file picker of copying the resource, or creating a reference to the external resource. The reference in this case would be the UUID returned by the file picker. If the user chooses to create a reference then the call to getFile(UUID) would be omitted when using the file picker, and is instead invoked every time the item is viewed. If the item retrieval requires authentication then the repository plugin will perform the authentication.

The Hive team have partially implemented solution number 2, however the resource has to be added as a URL which is not ideal. 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.

eg: http://hive43demo.harvestroad.com.au/moodle2/repository/hive/view.php/5/50/812/peugeot.jpg

In the above URL we have

* http://hive43demo.harvestroad.com.au/moodle2 => moodle server
* /repository/hive => Hive repository plug-in
* /view.php => Hive repository plug-in stream.er 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 needs to be passed back to getURL(UUID) or getFile(UUID)

To summarise, it would be useful if Moodle could store the UUID of the picked resource rather than downloading the resouce per se. The UUID can then be used at request time in order to stream the resource via getFile or to create an Url to it via getUrl.