API Request: Document Upload create only a Corrupt File within M-Files

Hello,

I am currently struggling with uploading documents to M-Files via the REST API. I am using a Laravel PHP application to create the request. From the technical side, the following works so far:
• Authentication
• Creating an UploadFile
• Creating a SingleFileDocument or MultiFileDocument

However, the file in M-Files has the correct filename and file type but is always just an empty container. The actual document content is never uploaded and the file is corrupt.

What am I missing?


UploadFileRequest

CreateSingleFileDocument

Best regards

Sebastian

Parents
  • The response of the second request is:

    {
    "Title":"m-files",
    "EscapedTitleWithID":"m-files (ID 247).pdf",
    "DisplayID":"247",
    "ObjVer":{
    "Version":3,
    "VersionType":4,
    "ID":247,
    "Type":0
    },
    "Class":207,
    "CheckedOutAtUtc":"1601-01-01T00:00:00Z",
    "CheckedOutAt":"1601-01-01T00:00:00Z",
    "LastModifiedUtc":"2024-11-22T13:21:27Z",
    "LastModified":"2024-11-22T13:21:27Z",
    "ObjectCheckedOut":false,
    "ObjectCheckedOutToThisUser":false,
    "CheckedOutTo":0,
    "SingleFile":true,
    "HasRelationshipsFrom":false,
    "HasRelationshipsTo":false,
    "HasRelationshipsFromThis":false,
    "HasRelationshipsToThis":false,
    "HasAssignments":false,
    "Deleted":false,
    "IsStub":false,
    "ThisVersionLatestToThisUser":true,
    "CreatedUtc":"2024-11-22T13:21:22Z",
    "Created":"2024-11-22T13:21:22Z",
    "Files":[
    {
    "Name":"m-files",
    "EscapedName":"m-files.pdf",
    "Extension":"pdf",
    "Size":236874,
    "LastModified":"2024-11-22T13:21:24Z",
    "ChangeTimeUtc":"2024-11-22T13:21:24Z",
    "ChangeTime":"2024-11-22T13:21:24Z",
    "CreatedUtc":"2024-11-22T13:21:22Z",
    "CreatedDisplayValue":"22.11.2024 13:21",
    "LastModifiedDisplayValue":"22.11.2024 13:21",
    "FileGUID":"{424128F4-FF05-4E00-A84E-54A8E4088F44}",
    "ID":280,
    "Version":1,
    "FileVersionType":3
    }
    ],
    "VisibleAfterOperation":true,
    "PathInIDView":"0\\0-999\\247\\S\\v3",
    "LastModifiedDisplayValue":"22.11.2024 13:21",
    "CheckedOutAtDisplayValue":"01.01.1601 00:00",
    "CreatedDisplayValue":"22.11.2024 13:21",
    "ObjectVersionFlags":2,
    "Score":0,
    "LastAccessedByMe":"2024-11-22T13:21:25Z",
    "AccessedByMeUtc":"2024-11-22T13:21:25Z",
    "AccessedByMe":"2024-11-22T13:21:25Z",
    "ObjectGUID":"{DA93DAF1-C28E-4B75-BEA8-B77A3B39DC64}",
    "ObjectCapabilityFlags":-1,
    "ObjectFlags":68,
    "propertyID":0,
    "LatestCheckedInVersion":3,
    "BaseProperties":[
    
    ]
    }

Reply
  • The response of the second request is:

    {
    "Title":"m-files",
    "EscapedTitleWithID":"m-files (ID 247).pdf",
    "DisplayID":"247",
    "ObjVer":{
    "Version":3,
    "VersionType":4,
    "ID":247,
    "Type":0
    },
    "Class":207,
    "CheckedOutAtUtc":"1601-01-01T00:00:00Z",
    "CheckedOutAt":"1601-01-01T00:00:00Z",
    "LastModifiedUtc":"2024-11-22T13:21:27Z",
    "LastModified":"2024-11-22T13:21:27Z",
    "ObjectCheckedOut":false,
    "ObjectCheckedOutToThisUser":false,
    "CheckedOutTo":0,
    "SingleFile":true,
    "HasRelationshipsFrom":false,
    "HasRelationshipsTo":false,
    "HasRelationshipsFromThis":false,
    "HasRelationshipsToThis":false,
    "HasAssignments":false,
    "Deleted":false,
    "IsStub":false,
    "ThisVersionLatestToThisUser":true,
    "CreatedUtc":"2024-11-22T13:21:22Z",
    "Created":"2024-11-22T13:21:22Z",
    "Files":[
    {
    "Name":"m-files",
    "EscapedName":"m-files.pdf",
    "Extension":"pdf",
    "Size":236874,
    "LastModified":"2024-11-22T13:21:24Z",
    "ChangeTimeUtc":"2024-11-22T13:21:24Z",
    "ChangeTime":"2024-11-22T13:21:24Z",
    "CreatedUtc":"2024-11-22T13:21:22Z",
    "CreatedDisplayValue":"22.11.2024 13:21",
    "LastModifiedDisplayValue":"22.11.2024 13:21",
    "FileGUID":"{424128F4-FF05-4E00-A84E-54A8E4088F44}",
    "ID":280,
    "Version":1,
    "FileVersionType":3
    }
    ],
    "VisibleAfterOperation":true,
    "PathInIDView":"0\\0-999\\247\\S\\v3",
    "LastModifiedDisplayValue":"22.11.2024 13:21",
    "CheckedOutAtDisplayValue":"01.01.1601 00:00",
    "CreatedDisplayValue":"22.11.2024 13:21",
    "ObjectVersionFlags":2,
    "Score":0,
    "LastAccessedByMe":"2024-11-22T13:21:25Z",
    "AccessedByMeUtc":"2024-11-22T13:21:25Z",
    "AccessedByMe":"2024-11-22T13:21:25Z",
    "ObjectGUID":"{DA93DAF1-C28E-4B75-BEA8-B77A3B39DC64}",
    "ObjectCapabilityFlags":-1,
    "ObjectFlags":68,
    "propertyID":0,
    "LatestCheckedInVersion":3,
    "BaseProperties":[
    
    ]
    }

Children
  • I'm not sure I understood all of that (I was hoping for just the raw request, but it has a lot more information there which I'm parsing).  It looks like it stored *something*, but that the something was wrong.  The response of the second request seems to indicate a 236k file, but the total content length specified in the first request was 12k...  That's not right.

    I'd really like to see the actual raw HTTP request for the first request.  My suspicion is that it's the multipart form data which is causing an issue.  Can you alter it to use the application/octet-stream version at M-Files Web Service: Temporary upload (where the request body simply contains a single file content)?

  • Hi Craig

    Thank you very much for your reply.

    I did some additional research on sending such requests and came across a suggestion on Stack Overflow to add the name “file” when attaching the file content. This seemed to resolve the issue of a corrupt file in M-Files.



    Many thanks for your help!

    Best regrads

    Sebastian