cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Update: Find information on Dropbox support during COVID-19 here
Close

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: 
Highlighted

File properties

Explorer | Level 4

Can anyone tell me why exactly I need to create a team to add file attributes to a file?

All I want to do is add a single attribute called "FileParentIdentifier" (which will hold a string value i.e name of folder".

It is very easy to add a custom attribute to file in Google Drive SDK.

But in Dropbox, we need to create a team, then create a template, then add file properties.

I have read the document but still confused if I need to create a Business Dropbox or not. I am currently not using business API. 

 

If I require a team, then how will this affect users of my app. 

 

 

1 Accepted Solution

Accepted Solutions
Highlighted

Re: File properties

Dropboxer
Dropboxer
A "team" refers to a Dropbox Business level collection of accounts. If you're interested, you can find more information here:

https://www.dropbox.com/business

Note that you don't need a Dropbox Business team to use the file properties functionality on the Dropbox API though:

https://www.dropbox.com/developers/documentation/http/documentation#file_properties

You can use a "full Dropbox" app to create templates that you can apply to files, whether or not the linked account is part of a Business team. (There is also a concept of templates owned by teams, but that is not required.)

So, in short, you can:
1. Register a full Dropbox app, if you haven't already: https://www.dropbox.com/developers/apps/create
2. Connect a user using the OAuth flow: https://www.dropbox.com/developers/reference/oauth-guide
3. Create a template using/2/file_properties/templates/add_for_user : https://www.dropbox.com/developers/documentation/http/documentation#file_properties-templates-add_fo...
4. Add file properties for your template to any number of files using /2/file_properties/properties/add: https://www.dropbox.com/developers/documentation/http/documentation#file_properties-properties-add

View solution in original post

9 Replies 9
Highlighted

Re: File properties

Dropboxer
Dropboxer
A "team" refers to a Dropbox Business level collection of accounts. If you're interested, you can find more information here:

https://www.dropbox.com/business

Note that you don't need a Dropbox Business team to use the file properties functionality on the Dropbox API though:

https://www.dropbox.com/developers/documentation/http/documentation#file_properties

You can use a "full Dropbox" app to create templates that you can apply to files, whether or not the linked account is part of a Business team. (There is also a concept of templates owned by teams, but that is not required.)

So, in short, you can:
1. Register a full Dropbox app, if you haven't already: https://www.dropbox.com/developers/apps/create
2. Connect a user using the OAuth flow: https://www.dropbox.com/developers/reference/oauth-guide
3. Create a template using/2/file_properties/templates/add_for_user : https://www.dropbox.com/developers/documentation/http/documentation#file_properties-templates-add_fo...
4. Add file properties for your template to any number of files using /2/file_properties/properties/add: https://www.dropbox.com/developers/documentation/http/documentation#file_properties-properties-add

View solution in original post

Highlighted

Re: File properties

Explorer | Level 4
Thank you for your reply .
I have already tried above method .
I am using full dropbox app and using dropbox sdk.
I tried to upload a file with property groups , (I created template, then created property field using property field init method , added to property group array. For the property group template_id, I used same template id obtained in response when creating template).
But some how , it is failing . I could successfully upload a file, but metadata of uploaded file do not contain property group parameter.
I was able to figure out the error. It is "template do not fit ".
I have already googled lot for this error , but do not know what is going wrong .

I have one more confusion, do we need to create a separate template for each file . If not, how do I obtain single template ID I already created for all files.
Highlighted

Re: File properties

Dropboxer
Dropboxer

It sounds like you're referring to the 'does_not_fit_template' error, which is documented as:

"One or more of the supplied property fields does not conform to the template specifications."

 

That means that the property fields that you're attempting to set for that file do not match the template you are using. You'll need to change your code to match the template you're using.

 

You do not need to create a new template for each file. You can use a single template on any number of files. You can use /2/file_properties/templates/list_for_user to list existing templates.

 

By the way, those are links to the documentation for the HTTPS endpoints themselves, but we recommend using one of the official SDKs if possible. Those have corresponding native methods for the HTTPS endpoints. You did mention you're using an SDK, but you didn't mention which one.

Highlighted

Re: File properties

Explorer | Level 4

Dropbox SDK I am using is "SwiftyDropbox"

 

Below is code snippet.

 

               //create template
                let template = FileProperties.PropertyFieldTemplate(name: "FileTemplate", description_: "File's Custom Properties Here", type: .string_)
                //add template
                client?.file_properties.templatesAddForUser(name: "User", description_: "Template for User", fields: [template]).response(completionHandler: { (templateResult, error) in
                    if let templateID = templateResult?.templateId {
                        //upload file using property groups
                        //create custom file attribute using property field
                       let field = FileProperties.PropertyField(name: "ParentFolderID", value: "123456")
                        //create property group, add template id and fields
                        let propertyGroup = FileProperties.PropertyGroup(templateId: templateID, fields: [field])

                        //upload file with above property group
                        let url = AppDirectory.albums.locationUrl.appendingPathComponent("15331256694236.png")

                        client?.files.upload(path: "/AppFolder/\(Date().toString).png", mode: .add, autorename: false, clientModified: Date(), mute: true, propertyGroups: [propertyGroup], input: url).response(completionHandler: { (metadata, error) in

                                print(metadata)

                        })                       
                    }
                })

I am getting 'does_not_fit_template' error.

I have followed the same steps. Rather than adding property groups separately using properties/add,  I am adding groups while uploading a file. Am I missing anything?

Highlighted

Re: File properties

Dropboxer
Dropboxer

It looks like the issue is that you're using a different field name when creating the template and then when trying to apply it later. I.e.:

let template = FileProperties.PropertyFieldTemplate(name: "FileTemplate", description_: "File's Custom Properties Here", type: .string_)

But then:

let field = FileProperties.PropertyField(name: "ParentFolderID", value: "123456")

That name "ParentFolderID" should be "FileTemplate" (or whatever you want it to be, as long as you're consistent).

Highlighted

Re: File properties

Explorer | Level 4

So template itself is custom attribute. (I was dumb to understand that).
I corrected the code and uploaded a file, uploaded with no error. However, propertyGroups from metadata (upload response) is nil.

 

response from uploading file looks like this.

 

{
    "client_modified" = "2018-08-03T04:34:16Z";
    "content_hash" = fea824f165374189797de317f75058467ddbec03b95755eee30e9612b6c6929e;
    id = "id:vPJIFqqKgdAAAAAAAAABiQ";
    name = "153327085668483.png";
    "path_display" = "/AppFolder/153327085668483.png";
    "path_lower" = "/appfolder/153327085668483.png";
    rev = 2feb83ead00;
    "server_modified" = "2018-08-03T04:34:29Z";
    size = 250930;
}

 When I tried to print metadata?.propertyGroups, it returns nil :(

 

One more confusion, Is template id constant ? ( Can I store the templateID in my realm database, so that I don't have to call

templatesListForUser method again and again )

Highlighted

Re: File properties

Explorer | Level 4

It looks like property groups are added successfully , but it isn't showing in metadata of uploaded file. 

 

I tried to get metadata of same file using below method. 

 

 client?.files.getMetadata(path: "/Ninja/153327085668483.png", includeMediaInfo: true, includeDeleted: false, includeHasExplicitSharedMembers: false, includePropertyGroups: FileProperties.TemplateFilterBase.filterSome(["ptid:LNRGA28Fu5AAAAAAAAAAtg"])).response(completionHandler: { (meta, error) in
                                    print(meta)
                                })

response

{
    "client_modified" = "2018-08-03T04:34:16Z";
    "content_hash" = fea824f165374189797de317f75058467ddbec03b95755eee30e9612b6c6929e;
    id = "id:vPJIFqqKgdAAAAAAAAABiQ";
    name = "153327085668483.png";
    "path_display" = "/Ninja/153327085668483.png";
    "path_lower" = "/ninja/153327085668483.png";
    "property_groups" =     (
                {
            fields =             (
                                {
                    name = ParentFolderID;
                    value = A123456;
                }
            );
            "template_id" = "ptid:LNRGA28Fu5AAAAAAAAAAtg";
        }
    );
    rev = 2feb83ead00;
    "server_modified" = "2018-08-03T04:34:29Z";
    size = 250930;
}

Thank you Greg for your replies

Highlighted

Re: File properties

Dropboxer
Dropboxer
Yes, that's expected. The property values won't be returned in the metadata from the upload itself. A successful response as you're receiving does indicate that is was successfully submitted though.

You need to call and explicitly request the property values, as you have done.

And yes, the template ID for a given template doesn't change, so you can and should store and re-use it.
Highlighted

Re: File properties

Explorer | Level 4
Okay... Thank you.
Polls
Do you know how to organize your files and folders?
We have created a guide on folder best practice, so you can get organized now check it out here.

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Need more support?