upload file via Soap

Have a great idea for extending Zimbra? Share ideas, ask questions, contribute, and get feedback.
Post Reply
CristinaB
Posts: 3
Joined: Fri Sep 12, 2014 11:29 pm

upload file via Soap

Post by CristinaB »

Hi,
Could you, please, tell me how to compose the Soap message for uploading/downloading a file to Zimbra?

I have seen something about FileUploadServlet, but I don't know how to use it..

Help me, please.. :rolleyes:
Thank you,

Cris.
BallaK
Posts: 4
Joined: Fri Sep 12, 2014 11:27 pm

upload file via Soap

Post by BallaK »

I need it too, please help. How to use the FileUploadServlet. An example would be perfect.
dkarp
Elite member
Elite member
Posts: 1410
Joined: Fri Sep 12, 2014 9:52 pm

upload file via Soap

Post by dkarp »

Please look at ZimbraServer/docs/file-upload.txt in the source distribution and let us know if that's not good enough.
You can also do a GET or PUT to the REST interface to fetch or add a file.
CristinaB
Posts: 3
Joined: Fri Sep 12, 2014 11:29 pm

upload file via Soap

Post by CristinaB »

OK. Thank you for your response. After a few tests we got an example running, but another problem appeared : the response doesn't seem to be correct. Here it is :






And the SAVE_DOCUMENT_REQUEST replies Cannot create (SoapFaultException).
BallaK
Posts: 4
Joined: Fri Sep 12, 2014 11:27 pm

upload file via Soap

Post by BallaK »

We managed to do the upload part.

Any suggestions from where to start in order to download ?
manawa
Posts: 5
Joined: Mon Feb 15, 2016 7:02 am

Re: upload file via Soap

Post by manawa »

dkarp wrote:Please look at ZimbraServer/docs/file-upload.txt in the source distribution and let us know if that's not good enough.

Yes, please, an example of how to get the AID would be very very helpful !
The "file-upload.txt" doesn't mention the ID of the uploaded file being returned.
And the SOAP API requires this ID to send a message with attachment.

Thanks
kLamda
Posts: 1
Joined: Thu Dec 16, 2021 8:04 pm

Re: upload file via Soap

Post by kLamda »

BallaK wrote:We managed to do the upload part.

Any suggestions from where to start in order to download ?
Can you kindly provide the body of the request you made to the Zimbra SOAP API for uploading the file? An example would be quite helpful.
User avatar
jeastman
Zimbra Employee
Zimbra Employee
Posts: 86
Joined: Tue Mar 29, 2016 1:36 pm

Re: upload file via Soap

Post by jeastman »

Uploading files to Zimbra is basically a 2-step process. You need to upload the actual file content and then send a request to save the document.

To upload the file, you actually call the FileUploadServlet. This is not a SOAP request, just a POST to the appropriate URL with the content. You will need to specify a couple of things with the request.

ZM_AUTH_TOKEN - in the cookie HTTP header on the request.
CONTENT_TYPE - CONTENT_TYPE HTTP header
CONTENT_DISPOSITION - CONTENT_DISPOSITION HTTP header with "attachment: filename="myfile.txt"" fo the value.

This will return a plain text string with the ID of the uploaded content. For example:

Code: Select all

18baa043-394f-42ae-be8a-110b279cb696:cc2f2fdf-7957-4412-aa83-6433662ce5d0
To actually save the document, you will use the SaveDocumentRequest (see https://files.zimbra.com/docs/soap_api/ ... ument.html).

The important fields below are:

name - the name of the file
ct - the file content type
l - the id of the parent folder
upload:id - the id from the previous step

Code: Select all

{
  "Header": {
    "context": {
      "userAgent": {
        "version": "1.0",
        "name": "my_uploader"
      },
      "account": {
        "_content": "your_name@example.com",
        "by": "name"
      },
      "authToken": "XXXX",
      "_jsns": "urn:zimbra"
    }
  },
  "Body": {
    "SaveDocumentRequest": {
      "_jsns": "urn:zimbraMail",
      "doc": {
        "name": "myfile.txt",
        "ct": "text/plain",
        "l": 1021,
        "upload": {
          "id": "18baa043-394f-42ae-be8a-110b279cb696:cc2f2fdf-7957-4412-aa83-6433662ce5d0"
        }
      }
    }
  }
}
The content type and file name may seem redundant in both places, and in fact I believe they are. It is probably only needed in the SOAP call, but I do it both places anyway.

Some additional documentation is available in the server docs:
https://github.com/Zimbra/zm-mailbox/bl ... upload.txt
https://github.com/Zimbra/zm-mailbox/bl ... cument.txt

You will also find the information there on downloading documents.

Hope this helps.
John Eastman
Post Reply