I can’t send file via post using "Xios"

Asked

Viewed 672 times

0

Guys good day I’m with a project in Ode.js and I stuck in a situation,I already researched a lot and I can not find a solution so far. I am creating a Rest api that is consumed through Axios a GLPI (so-called tools) Rest api, I can make most calls but it has a "post" call that my Node.js api receives a form-date and need to pass the file that comes in the request to the other glpi api. I tried the multer however as far as I saw the multer only serves if I want to upload the file to the project server nodejs, but what I need is to send the file to the api glpi through the api Node.js so I am not able to send this file as a parameter in the request , I tried req.file but it doesn’t work.

Note: Before I asked "why then not make the request directly api final glpi", I have a particularity in the design I need to do in this architectural form

    const options2 = {
        headers: {
            'Content-Type': 'multipart/form-data',
            'Session-Token': "xxxxxxxxxxxxxxxxx",
            'App-Token': "xxxxxxxxxxxxxxxxx",
        }
    }

const baseUrl = 'http://localhost/glpi/apirest.php/ticket/';


 followup: async(req) => {
    //console.log(req.file);
    await axios.post(`${baseUrl}${req.body.id}/TicketFollowup/`, {
            "input": {
                "tickets_id": `${req.body.id}`,
                "content": "test 123 follow",
            }
        }, options2,req.file)
        .then(response => res.send(response.data))
        .catch(error => console.log(error));

}

the code snippet above is already in the layer "service" being called in the layer "Routes" already tried from the console.log(req.file) it brings the data of the file I sent by Postman, however when I try to send this error:

date: [ 'ERROR_UPLOAD_FILE_TOO_BIG_POST_MAX_SIZE', 'The file seems Too big' ] }, isAxiosError: true, toJSON: [Function] }

being that if send by glpi api the same file I can send without problems .

  • Try to set the Boundary in Content-Type to the limits of the parameter

1 answer

0

Are you using localhost? yes, this seems to me php.ini configuration error. If you are using Xampp it is very simple to get to the configuration because xammp already gives this shortcut. if it is in xampp you should look up php.ini and edit the line:

upload_max_filesize=2M

to receive files larger than 2M. example: 10M.

  • I did not only collect localhost at the example level, but as I said if I request directly to the server with the glpi api directly I can send the same file.

  • So even on the server you should search for your php.ini and change the line upload_max_filesize=2M

  • It has this line that also influences: post_max_size=8M Don’t forget to restart apache after making these changes.

  • the file I am sending it is 1kb in size and as I said earlier the server is receiving the same file via glpi direct api.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.