REST API

How to Upload a File in Nuxeo Platform Using REST API Batch Processing Endpoint

Updated: October 16, 2020

The Platform provides facilities for uploading binaries under a given "batch id" on the server, and then to reference that batch id when posting a document resource, or for fetching it from a custom automation chain. For instance if you need to create a file with some binary content, first you have to upload the file into the batchManager. It's a place on the system where you can upload temporary files to bind them later.

  1. For that you have to generate yourself a batchId, which will identify the batch : let's say mybatchid.

    POST http://localhost:8080/nuxeo/api/v1/automation/batch/upload
    X-Batch-Id: mybatchid
    X-File-Idx:0
    X-File-Name:myFile.zip
    -----------------------
    The content of the file
    

    Or with curl:

    curl -H "X-Batch-Id: mybatchid" -H "X-File-Idx:0" -H "X-File-Name:Sites.zip" -F [email protected] -u Administrator:Administrator http://localhost:8080/nuxeo/site/automation/batch/upload
    
  2. You may verify the content of your batch with the following request.

    GET http://localhost:8080/nuxeo/site/automation/batch/files/mybatchid
    [{"name":"Sites.zip","size":115090}]
    
  3. Next you have to create a document of type File and attach the Blob to it by using the specific syntax on the file:content property.

    POST http://localhost:8080/nuxeo/api/v1/path/default-domain/workspaces/myworkspace
    {  
      "entity-type": "document",
      "name":"myNewDoc",
      "type": "File",  
      "properties" : {
        "dc:title":"My new doc",
        "file:content": {
          "upload-batch":"mybatchid",
          "upload-fileId":"0"
        }
      }
    }
    

    Or with curl:

    curl -X POST -H 'Content-Type: application/json' -u Administrator:Administrator -d '{"entity-type": "document", "name": "myNewDoc", "type": "File", "properties": {"dc:title": "My new doc", "file:content": {"upload-batch": "mybatchid", "upload-fileId": "0"}}}' http://localhost:8080/nuxeo/api/v1/path/default-domain/workspaces/myworkspace
    
  4. Finally you now can access the content of your file by pointing to the following resource:

    GET http://localhost:8080/nuxeo/api/v1/path/default-domain/workspaces/myworkspace/myNewDoc/@blob/file:content