Open zhiyuli opened 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":
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)
@sblack-usu is every file uploaded to CompositeResource a GenericLogicalFile by default?
@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
options = { "file_path": "mailchimp.txt", "hs_file_type": "Generic" } hs.resource(resource_id).functions.set_file_type(options)
f_metadata = {....} hs.resource(resource_id).files.metadata(file_id, f_metadata
@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....
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.
@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.
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.
options = { "file_path": "mailchimp.txt", "hs_file_type": "Generic" } hs.resource(resource_id).functions.set_file_type(options)
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)
hs.resource(resource_id).files.metadata(file_id, f["metadata"]) Works for ReferencedFile, But it Does Not work for GernericFileType