Closed xacobofg closed 1 year ago
Hi,
Can you provide the payload that can be used to reproduce this issue ?
I tested a call with following payload on POST http://glpi/apirest.php/Document/
and it successfully created the file:
{
"headers": {
"App-Token": "********",
"Session-Token": "********"
},
"multipart": [
{
"name": "uploadManifest",
"contents": "{\"input\":{\"name\":\"API upload test\",\"_filename\":[\"test.txt\"]}}"
},
{
"name": "filename1229194340[]",
"contents": "A simple text file\nto test API upload.\n\n",
"filename": "test.txt"
}
]
}
No feedback, I close
Code of Conduct
Is there an existing issue for this?
Version
10.0.3
Bug description
When uploading a document through the API requests if the document name is not longer than 23 characters it returns the error 'Unauthorized file type'.
Relevant log output
No response
Page URL
apirest.php/Document
Steps To reproduce
Your GLPI setup information
Información sobre la instalación y configuración del sistema
Server
GLPI constants
Libraries
SQL replicas
Notifications
Plugins list
Locales overrides
Anything else?
I think the error is caused in the class
src/GLPIUploadHandler.php
line 156$val->prefix = substr($val->name, 0, 23);
If the name has less than 23 characters it stores in 'prefix' the extension of the document causing that when the function
moveUploadedDocument
of the classsrc/Document.php
is executed it removes the extension at line 1152$filename = str_replace($prefix, '', $filename);