I've just started using the Dropbox Python API, but am a bit confused on how to add custom metadata to new or exists files.
I've tried to defined my own PropertyGroup with the data stored in a PropertyField (as shown in the code below). However, passing this as a parameter of dbx.files_upload() causes the process to freezes up. Should the template_id of the property group be defined differently?
data = dropbox.file_properties.PropertyField('foo', 'bar') my_property_group = dropbox.file_properties.PropertyGroup() my_property_group .template_id = '/|test_template' my_property_group .fields = [data] with open(r'C:\test_file.txt', "rb") as f: dbx.files_upload(f.read(), '/test_file.txt', mute = True, property_groups=[my_property_group ])
Any help on this would be much appreciated!
Thanks for the report. I'll be happy to help with this, but I could use a few points of clarification:
I also notice that you're not using the return value of 'dbx.files_upload'. You may want to print or save that value somewhere for reference. If the call succeeds, it will contain the metadata of the uploaded file.
Thanks for pointing a few things out that I seem to have overlooked. The freezing up, ended up being due to wrong formatting and an incorrect unique id for the custom string template - now sourced correctly using the following code:
template = dropbox.file_properties.PropertyFieldTemplate(name="MyTemplate", description="description",type=dropbox.file_properties.PropertyType.string) my_template_id = dbx.file_properties_templates_add_for_user("MyTemplate","description",[template]).template_id data = dropbox.file_properties.PropertyField(name='MyTemplate', value='foobar')
Thanks for following up. I'm glad to hear you already sorted most of this out.
Have a question? Our Dropbox Community is here to help you find an answer!
You won’t have to wait too long for a reply, but why not learn more about the Community while you’re here.
Not the right discussion for you? Find out what else our Community has to say about API Support.
Or, search our Help Center for even more.