Hello,
I'm trying to build a simple program using PHP to create a new object within an attachment file included inside the object (docx) but always return corrupt / unreadable. But it is working well for PDF attachment file.
Code snippet :
Hello,
I'm trying to build a simple program using PHP to create a new object within an attachment file included inside the object (docx) but always return corrupt / unreadable. But it is working well for PDF attachment file.
Code snippet :
I haven't used PHP in a few years, but I would recommend that you use something like a HTTP debugging proxy to see what HTTP requests are going back and forth, then compare that to the examples on the Developer Portal (and/or post them here). My guess is that it's to do with how PHP is adding the file data to the "files" endpoint, or perhaps that some HTTP headers are missing/added.
I haven't used PHP in a few years, but I would recommend that you use something like a HTTP debugging proxy to see what HTTP requests are going back and forth, then compare that to the examples on the Developer Portal (and/or post them here). My guess is that it's to do with how PHP is adding the file data to the "files" endpoint, or perhaps that some HTTP headers are missing/added.
Hi Craig,
Thanks for the response.
I have tried with Postman, but the result is the same.
Step 1 : Requesting the UploadID (http:localhost/REST/files)
Step 2 : Creating the object (localhost/.../0)
The JSON value attached is :
What's wrong here? The docx file is then not usable? Does the object look okay (correct extension, etc.) in M-Files?
If so then I guess it's something to do with the first request; the one that uploads the file. Take a look at the request headers; perhaps it's being transferred in a way that the server doesn't understand..
I have fixed this issue by changing file_get_content(), the PHP built in function (for some reason it is not working well for uploading the docx attachment but working for pdf attachment) to CURLFile() - that is working for all kinds of attachment's extension. Also, I set the header with no set of Content-Type.
© 2024 M-Files, All Rights Reserved.