Upload file and add properties

Showing results for 
Search instead for 
Did you mean: 
Active Member II

Upload file and add properties

I am trying to upload a file using python requests lib.

I have gotten the file upload working. using 

requests=(files={'filedata': open(file)})

But how can I add properties to the file to upload?

I have some links to possible solutions, but I have not gotten any of them to work.

1) https://stackoverflow.com/questions/32585800/convert-curl-request-to-python-requests-request

2) https://stackoverflow.com/questions/66796487/alfresco-basic-authentication-works-with-curl-but-not-w... (my post)


Content-Length: 248588
Content-Type: multipart/form-data; boundary=2eda0224894a7955aa73990f6d06b87e

Content-Disposition: form-data; name="properties"

Content-Disposition: form-data; name="properties"

Content-Disposition: form-data; name="properties"


5 0 obj
<</Length 6 0 R/Filter /FlateDecode>>
3 Replies
Active Member II

Re: Upload file and add properties

Content-Length: 248595
Content-Type: multipart/form-data; boundary=b4407dae6a30a4e93ba1c0e857cce06b

Content-Disposition: form-data; name="data"
Content-Type: application/json

{"properties": {"cm:title": "info", "cm:description": "info", "cm:author": info}}
Content-Disposition: form-data; name="filedata"; filename="application_of_dependency_graphs_to_security_protocol_analysis_0.1_T-5-4.pdf"

5 0 obj

I got it into a better state. But it still doesn't read the fields. The problem is things like parameter names. Alfresco Backend reads the file only with parameter 'filedata'. So what is the parameter 'data' or 'json' supposed to be? Is the structure wrong there?

Active Member II

Re: Upload file and add properties

I have a feeling you can't add the title/description/authors metadata in post request. 


I made a second PUT request right after a successful POST request ( you get the inserted object ID back with POST)

and i was able to add the props successfully

{"properties":{"cm:description":"blaah" etc. }

Alfresco Employee

Re: Upload file and add properties

Hi @Taaviansper 

I've just tested using the API to upload a document with metadata successfully. 

I've used Postman to test the API and it will generate code - here is the Python code:

import requests

url = "http://localhost/alfresco/api/-default-/public/alfresco/versions/1/nodes/-my-/children?alf_ticket=TICKET_1d41b867df221a4d0edcd161d4df7570f1a07f98"

payload={'name': 'Marketing Automation.ppt',
'autoRename': 'true',
'cm:title': 'Marketing Automation',
'cm:description': 'A powerpoint about marketing and automation',
'exif:manufacturer': 'Canon',
'cm:author': 'Eddie May'}
headers = {
  'Authorization': 'Basic dGVzdDp0ZXN0'

response = requests.request("POST", url, headers=headers, data=payload, files=files)


Note that in the payload I've set properties such as title & description. You can also see that it's a POST request.

The result in share is as follows:

MetadataMetadataYou can see from the creation date that I did it today (26 March 2021).

This should work from Alfresco 5.2 upwards. Here I'm testing against Community Edition 6.2.


Digital Community Manager, Alfresco Software.
Problem solved? Click Accept as Solution!