hydroshare / hs_restclient

Python client for the https://www.hydroshare.org REST API
BSD 3-Clause "New" or "Revised" License
6 stars 8 forks source link

hs.resource(resource_id).files.metadata(file_id, f["metadata"]) Does Not work for GenericFileType #99

Open zhiyuli opened 5 years ago

zhiyuli commented 5 years ago

hs.resource(resource_id).files.metadata(file_id, f["metadata"]) Works for ReferencedFile, But it Does Not work for GernericFileType

sblack-usu commented 5 years ago

What do you mean by generic file type? Pretty sure a ReferenceFile uses GenericLogicalFile. A regular file does not have a logical file type attached to it, so if you want to add metadata to a file you'll have to first set it as the type. You can do that in the UI with the dropdown box and selecting "add metadata to file": image

To do this in the api, do smething like this:

options = {
             "file_path": "mailchimp.txt",
             "hs_file_type": "Generic"
          }
hs.resource(resource_id).functions.set_file_type(options)
zhiyuli commented 5 years ago

@sblack-usu is every file uploaded to CompositeResource a GenericLogicalFile by default?

zhiyuli commented 5 years ago

@sblack-usu I just want to add metadata to a GenericLogicalFile file via api: Should I set file type first and then add metadata, like

step 1: set file to GenericLogicalFile

options = { "file_path": "mailchimp.txt", "hs_file_type": "Generic" } hs.resource(resource_id).functions.set_file_type(options)

step 2: find file_id

step 3: add metadata to file

f_metadata = {....} hs.resource(resource_id).files.metadata(file_id, f_metadata

zhiyuli commented 5 years ago

@sblack-usu Also I think it is better to standardize the use of filename and file_id. Currently some endpoints need filename but other need file_id....

sblack-usu commented 5 years ago

no, files don't have any logical file by default unless they're recognized as an aggregation. Apologies for the inconsistencies between file_id an dfile_path... this was inherited. I'm in favor of ditching file_ids completely. I can update metadata to take the path in this ticket as well. For backwards compatibility, I'll leave the file_id in there as well.

zhiyuli commented 5 years ago

@sblack-usu also in some cases, HS will rename uploaded files. one case I found was "my file.txt" got changed to "my_file.txt". if we choose to use filename as the identifier, the uploading/creation rest api should return the new filename HS saved, or return both file_id and filename.

sblack-usu commented 5 years ago

yeah, that's some functionality that came in to standardize file names. I voted for just blocking names with spaces, but it was decided we would change " " to "_". I agree it should return the resulting file name.

zhiyuli commented 5 years ago

step 1: set file to GenericLogicalFile doesnt work in HS RC1.19 + Client 1.3.1

options = { "file_path": "mailchimp.txt", "hs_file_type": "Generic" } hs.resource(resource_id).functions.set_file_type(options)

zhiyuli commented 5 years ago

fixed by changing "Generic" to "SingleFile". Thanks @sblack-usu options = { "file_path": f["file_name"], "hs_file_type": "SingleFile" } hs.resource(hs_id).functions.set_file_type(options)