This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Adding a new file to an existing object (javascript)

Hi,

I succeeded to update an existing file attached to an object via the API "REST/objects/0/{checkedOutObjectVersion.ObjVer.ID}/files/{checkedOutObjectVersion.Files[0].ID}/content.aspx?_method=PUT", although that was tough. I need now to add a new file to an existing object. From the C# example at https://developer.m-files.com/APIs/REST-API/Updating-Objects/#updating-an-existing-file, I figured out that the API is "REST/objects/0/{checkedOutObjectVersion.ObjVer.ID}/{checkedOutObjectVersion.ObjVer.Version}/files/upload.aspx". However, it is not clear at all how I pass the file name and file extension through the API, mostly since I am using an application/octet-stream content type where I cannot mix JSON data and binary data.

Any help would be appreciated, as well as javascript examples.

Thank you in advance,

Gilles Gerlinger

Parents
  • File upload with REST/files seems OK. It returned the following data:

    {"UploadID":10,"Size":1473469,"FileInformationType":0}

    After adding Title and Extension it becomes:

    {"UploadID":10,"Size":1473469,"FileInformationType":0,"Extension":"zip","Title":"SCORM_What_5G_is_and_what_it_isnt_TD10721-W-1800-kghuhxxs"}

    Then after adding the file to the object, here is the error message I have:

    {
      Status: 400,
      URL: '/objects/0/60893/latest/files/upload',
      Method: 'POST',
      Exception: { Name: 'ArgumentException', Message: 'Malformed data.' },
      Stack: 'Error reference ID: 7e75e1c5-f3b5-4754-8f50-061da13262d3',
      Message: 'Malformed data.',
      IsLoggedToVault: true,
      IsLoggedToApplication: true,
      ExceptionName: 'ArgumentException'
    }
     

  • I finally made it by calling the API "

    objects/${object.Type}/${object.ID}/latest/files/${uploadID}/title?_method=PUT to change the title of the uploaded file (which was Unnamed). This was not part of the C# example, I had to dig into the API docuemtation to find this...
Reply Children