CS REST API: How do you upload a newer version of a file?

Options

If a file already exists, how do you upload a newer version of a file? Posting and Putting are giving me a 400 error.

Comments

  • Ferdinand Prantl
    Ferdinand Prantl E Community Moderator
    Options

    Make a POST to .../nodes/{node_id}/versions with the file parameter containing the file content, using the multipart/form-data content type. For example:

    var file = ..., // from a file input element. for example
        formData = new FormData();
    
    formData.append('file', file);
    
    $.ajax({
      url: '.../api/v1/nodes/12345/versions',
      type: 'POST',
      data: formData,
      processData: false,
      contentType: false
    });
    

    You will find the new version number in the response, is the upload succeeds. For example:

    {
      "id": 12345,
      "version_number": 2
    }