You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2023-09-22 14:58:01

Pcv12
Member
Registered: 2023-09-22
Posts: 2

Problem with upload files in GLPI 10.0.9

Hi!

Im working since 2 years on a project that integrates with two GLPI 9.5 API. One of them is used for human resources topics, and the other is used for tech issues.

Netx month, one of them wil be migrated to version 10.0.9 and, in developement tests, all the endpoints we call work fine except /Document

To operate with the API, we have a microservice developed in NodeJS 16.14 and for the calls we use Axios 0.26.1. The code is the same in both versions and in GLPI 9.5 everything works correctly.


To upload file, we use FormData interface. The headers and body code are these:

 
  const headers: any = {
    'Session-Token': sessionToken,
    'App-Token': appToken,
    ...data.getHeaders(),
   }

  data.append(
    'uploadManifest',
    `{"input":{"name":"${file.name}","_filename":"${file.name}","is_recursive":1}}`
  );
  
  data.append('filename[0]', file.data, file.name);

  const config: any = {
    method: 'POST',
    url: `${urlGLPI}/Document`,
    headers,
    data,
  };

Note: when we add Content-Lenght header with the file size, the file uploads empty

If we upload a small file (1 or 2 kb), it is uploaded correctly but if we try with a slightly larger file (14k), the API returns the error:

    Request failed with status code 400

    data: [
      'ERROR_UPLOAD_FILE_TOO_BIG_POST_MAX_SIZE',
      'The file seems too big'
      ]

The microservice is hosted in a Kubernetes cluster from which, if we launch curl commands to to the API to add the file, it works but from the code it does not.

Here is the curl that works, launched from the same cluster:

 
curl -X POST 'http://urlGLPI/Document' -H 'Session-Token: XXXXXXXXXX' -H 'App-Token: XXXXXXXXXX' -H 'Content-Type: multipart/form-data' -F 'uploadManifest={"input":{"name":"imagen.png","_filename":"imagen.png","is_recursive":1}}' -F filename[0]=@imagen.png -v

We have tried several options without success, such as:

  • Modify request headers

  • Use a higher Axios version

  • Modify Axios settings

To add more details, the GLPI 10.0.9 server is an Apache/2.4.53 (Red Hat Enterprise Linux), and the GLPI 9.5 server is an Apache (uknow version) running in a Ubuntu 20.04. All the request are HTTP protocol (developement environment)

Do we have to add any additional parameters or any different configuration in 10.0.9 version?

Thanks!

Offline

#2 2023-10-27 10:52:11

Pcv12
Member
Registered: 2023-09-22
Posts: 2

Re: Problem with upload files in GLPI 10.0.9

After a lot of time spent investigating possible causes, I have finally managed to solve this problem. In case it helps someone in the future, I am adding the solution here:

The error was that the new server where GLPI 10 is located requires, for security reasons, adding the "content-length" header calculated when making the POST request to upload the file. We have also added this header to the request that associates the ticket with the document.

In previous tests, we added this header incorrectly, which is why it wasn't working.

Offline

Board footer

Powered by FluxBB