'How to send binary data of a file in a request body?

Is there any way to send binary data of a file in body of a put request using nodejs and axios ?



Solution 1:[1]

you can use a FormData append your file to it , send it with axios then get it with multer in server side.

const data = new FormData()
data.append('multer_file_name', file, file.name)
axios.post("your_api", data, {
    headers: {
        accept: 'application/json',
        'Accept-Language': 'en-US,en;q=0.8',
        'Content-Type': undefined,
         },
}).then((response) => {
})

you can get your file like this if you have an input :

const file = document.getElementById('your_input_id').files[0]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1