cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Re: Setting Metadata on files - Python API

Setting Metadata on files - Python API

MorgsCode
Explorer | Level 3
Go to solution

Hello! 

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! 

 

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

Thanks for following up. I'm glad to hear you already sorted most of this out.

  • The PropertyType.other option is just a catch-all for forwards compatibility with any potential new PropertyType fields. It's not actually something you can use as an alternative to PropertyType.string. Currently the Dropbox API only supports the string type. What other data type in particular would you be looking to use? I'll be happy to pass it along as a feature request.
  • You can change the property values on an existing file without re-uploading it. To do so, you would use the file_properties_properties_update method and/or the file_properties_properties_overwrite method. (Be sure to read the documentation for information on the difference between the two.)

View solution in original post

3 Replies 3

Greg-DB
Dropbox Staff
Go to solution

Thanks for the report. I'll be happy to help with this, but I could use a few points of clarification:

  • What do you mean exactly when you say "the process to freezes up"? How are you checking this and what exactly do you see? Also, depending on the size of the file and your network connection, it may take some time to upload, so make sure you give it enough time to complete.
  • Is '/|test_template' the actual value you're sending, or is that just something you put there for this post in order to not post the actual ID? Actual template ID values should start with "ptid:", e.g., as returned by file_properties_templates_add_for_user or file_properties_templates_list_for_user

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.

MorgsCode
Explorer | Level 3
Go to solution

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')
  • Regarding the PropertyFieldTemplate the available types seems to be either 'string' or 'other'. Just curious, how you would use the PropertyType 'other' to store data?
  • Can property group data be altered on uploaded files or does it have to be added as part an upload process? 

Greg-DB
Dropbox Staff
Go to solution

Thanks for following up. I'm glad to hear you already sorted most of this out.

  • The PropertyType.other option is just a catch-all for forwards compatibility with any potential new PropertyType fields. It's not actually something you can use as an alternative to PropertyType.string. Currently the Dropbox API only supports the string type. What other data type in particular would you be looking to use? I'll be happy to pass it along as a feature request.
  • You can change the property values on an existing file without re-uploading it. To do so, you would use the file_properties_properties_update method and/or the file_properties_properties_overwrite method. (Be sure to read the documentation for information on the difference between the two.)
Need more support?