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

  • By the way, this is the error message returned by the APi : "The current endpoint is part of the 'MFWA' extension. Use 'X-Extensions' header or 'extensions' query parameter to specify the extension."

  • To be more precise:

    This is the object sent after the file content is successfully uploaded:

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

    and the error message:

    {
      Status: 405,
      URL: '/objects/0/60893/latest/files/upload',
      Method: 'POST',
      Exception: {
        Name: 'NotSupportedException',
        Message: "The current endpoint is part of the 'MFWA' extension. Use 'X-Extensions' header or 'extensions' query parameter to specify the extension."
      },
      Stack: 'Error reference ID: 4e095967-d8d8-4d78-89e2-2118ee0901b3',
      Message: "The current endpoint is part of the 'MFWA' extension. Use 'X-Extensions' header or 'extensions' query parameter to specify the extension.",
      IsLoggedToVault: true,
      IsLoggedToApplication: true,
      ExceptionName: 'NotSupportedException'
    }

  • 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...
  • So the api loads the unnamed file, and later you change the title with another api call?, i have a very similar issue whit python 

  • Indeed, I had to deep dive into the API documentation and make various tries before I found this way to add a new file to an object...

  • Hi,

    I m facing same error when adding file to an existing object. I tried your error but it don't work. it gives file not found error