This code snippet will show you how to delete a single file from a HydroShare rsource using the HydroShare API. This could be a useful function in the case where you need to replace a file in a resource with a newer updated version of the same resource. You could also use this function to allow your code to clean up a resource by deleting unneeded files. Keep in mind, that all deletions of files using this method are PERMENANT, so be careful ! But this feature works smoothly without any glitches, just try copying the resource id from the HTTP hyperlink when you open your resource in Hydroshare.
Our demonstration code here is comprised of two steps. Step 1 will query the resource and generate a list of files available therein. Step 2 will actually delete a selected file from a resource.
To try this on your own, you can use the code snippet below, or download the full javascript file that is used in this demonstration
from hs_restclient import HydroShare, HydroShareAuthBasic
auth = HydroShareAuthBasic(username='myusername', password='mypassword')
hs = HydroShare(auth=auth)
fname = 'somefile.txt'
resource_id = hs.deleteResourceFile('ID OF RESOURCE GOES HERE', fname)