Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

161
Vistas
CURL Command to NodeJS - PUT Request OctetStream

I need to make this curl command into a nodejs request, either using fetch, request or axios networking libraries

The request needs to PUT the file data to the URL

curl -v -H "Content-Type:application/octet-stream" --upload-file C:/Users/deanv/Pictures/test3.mp4 "https://www.example.com/file/upload"

I've tried using CurlConverter to convert my curl command to node code, but this doesn't work as I cant add the file data.

var fetch = require('node-fetch');

fetch('https://www.example.com/file/upload', {
    method: 'PUT',
    headers: {
        'Content-Type': 'application/octet-stream'
    }
});

All help appreciated. Thanks in advance.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Try this:

// setup modules
const fetch = require('node-fetch');
const FormData = require('form-data');
const fs = require('fs');
const path = require('path');

// setup paths
const pathToFile = 'C:/Users/deanv/Pictures/test3.mp4';
const uploadUrl = 'https://www.example.com/file/upload';

// create form, 'content-type' header will be multipart/form-data
const form = new FormData();

// read the file as stream
const fileStream = fs.createReadStream(path.resolve(pathToFile));

// add the file to the form
form.append('my_file', fileStream);

fetch(uploadUrl, {
        method: 'PUT',
        body: form
    }).then((res) => {
        console.log('done: ', res.status);
        return res.text();
    })
    .then((res) => {
        console.log('raw response: ', res);
    })
    .catch(err => {
        console.log('err', err);
    });
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda