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

Bad Request 400 when Uploading file to an object

I am getting below message when adding file to an existing object. I m using c#:

{"Status":400,"URL":"/objects/0/18222/latest/files/upload","Method":"POST","Exception":{"Name":"ArgumentException","Message":"Malformed data."},"Stack":"Error reference ID: ccff6cb1-a969-4574-beac-fe7bbeb2e7a6","Message":"Malformed data.","IsLoggedToVault":true,"IsLoggedToApplication":true,"ExceptionName":"ArgumentException"}

Below is my request:

{"UploadID":4,"Title":"test1234","Extension":"txt","Size":40,"FileInformationType":0,"TempFilePath":""}

Thanks

Parents
  • I think the data you send should be a collection.  So something like this:

    [{"UploadID":4,"Title":"test1234","Extension":"txt","Size":40,"FileInformationType":0,"TempFilePath":""}]

  • Hi Craig,

    Thanks for reply after your mentioned update, I am receiving below error message:

    {"ErrorCode":"11","Status":404,"URL":"/objects/0/18222/latest/files/upload","Method":"POST","Exception":{"Name":"COMException","Message":"Not found.","InnerException":{"Name":"MFilesException","Message":"Not found.","StackText":"Error reference ID: 56118aa7-47dd-4788-aa8c-d250dbef0754","ErrorCode":"11"}},"Stack":"Error reference ID: 56118aa7-47dd-4788-aa8c-d250dbef0754","Message":"Not found.","IsLoggedToVault":true,"IsLoggedToApplication":true,"ExceptionName":"COMException"}

  • So it seems that the request is now valid, but something in the content isn't valid.  Double-check all the various IDs in the request.

  • Hi Craig,

    There is really confusion about what is the correct path for I am uploading file to an existing object: I have used below options

    ">192.168.10.5/.../" + results1.Items[0].DisplayID + "/"+ results1.Items[0].ObjVer.Version + "/files/upload

    ">192.168.10.5/.../" + results1.Items[0].DisplayID + "/"+ results1.Items[0].ObjVer.ID + "/files/upload

    Also

    ">192.168.10.5/.../" + results1.Items[0].DisplayID + "/" + results1.Items[0].ObjVer.Version + "/files/upload

    All of them returning NotFound status code as above.

    Thanks for your suport

  • That doesn't look right.

    The URI should be "/objects/{objectTypeID}/{internalObjectID}/{version}/files/upload".  "version" can be the string "latest" in some situations too.

    Also be careful that the display ID may not be what you want.  Read more here: Internal and External IDs (m-files.com)

    You probably want:

    // Without a specific version number (always the latest one available to this user):
    var uri = "https://.../REST/objects/" + results1.Items[0].ObjVer.Type + "/" + results1.Items[0].ObjVer.ID + "/latest/files/upload";
    
    // With a specific verison number:
    var uri = "https://.../REST/objects/" + results1.Items[0].ObjVer.Type + "/" + results1.Items[0].ObjVer.ID + "/" + results1.Items[0].ObjVer.Version + "/files/upload";
    
    

  • I was following the below format as per the documentation (developer.m-files.com/.../) 

    localhost/.../{checkedOutObjectVersion.ObjVer.ID}/{checkedOutObjectVersion.ObjVer.Version}/files/upload.aspx

    I am checking your suggestion and will update.

    Thanks

Reply Children