Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
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.
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.
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?
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).
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 )
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 🙂
Hi there!
If you need more help you can view your support options (expected response time for a ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!