How to post a file to a remote URL using got?

201 Views Asked by At

I'm trying to post a file to a remote URL using got. But it is not working as expected.

I have tried the following

const headers = {
    "Content-Type": "image/png"
}

const requestProperties = {
    method: 'POST',
    url,
    headers,
    json: fs.createReadStream(file.path)
}

const response = await got(requestProperties);
1

There are 1 best solutions below

1
Sufail Kalathil On

Thank you @phil I have used body property instead of json.

const headers = {
    "Content-Type": "image/png"
}

const requestProperties = {
    method: 'POST',
    url,
    headers,
    body: fs.createReadStream(file.path)
}

const response = await got(requestProperties);