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

117
Vistas
passing binary data to rest-api

I want to upload a thumbnail to viemo api , and based on Vimeo doc, I must include the thumbnail file as binary data in the request body, I have to upload the thumbnail from the client side "fontend" and will send the request from the rest-api "backend" the problem is my rest-api can't receive the binary data, properly because I'm using express.js, is there any way to handle the binary data in the backend.

the steps as following:

client side sent thumbnail data => backend receive the data through the request body and send it to => endpoint

client side request

  const handleSubmit = (event) => {
    event.preventDefault();
    const formData = new FormData();
    formData.append('selectedFile', new Blob([selectedFile], { type: 'application/json' }));
    formData.append('uploadLink', uploadLink);

    const headers = {
      'Content-Type': 'application/json',
      Accept: 'application/vnd.vimeo.*+json;version=3.4',
    };

    try {
      axios
        .post(`${backendPostPath}/thumbnail-upload`, formData, {
          headers,
        })
        .then((response) => {
          applyThumbnial();
          console.log(`${uploadLink}link for upload`);
        });
    } catch (error) {
      console.log(error);
    }
  }; 

backend request can't receive the body request of frontend post as binary data,

const ThumbnailUpload = async (req, res) => {
  const { uploadLink } = req.body;
  const { selectedFile } = req.body;
  console.log(uploadLink);
  const clientServerOptions = {
    uri: `${uploadLink}`,
    encoding: null,
    body: JSON.stringify({
      name: uploadLink,
      file: selectedFile,
    }),
    method: 'PUT',
    headers: {
      'Content-Type': 'application/json',
      Accept: 'application/vnd.vimeo.*+json;version=3.4',
      Authorization: getVimeoAuthorization(),
    },
  };
  request(clientServerOptions, function (error, response) {
    if (error) {
      res.send(error);
    } else {
      const body = JSON.parse(response.body);
      res.send(body);
    }
  });
};

is there any way to make the backend request body fetch the binary data, as I getting the data as "undefined"

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

0

Sorry for late update, I solved this issue by using the same put request form the client side, as the put request don't require Vimeo access token, so you can use the same put request i mentioned above, and remove authentication from the header, like following

const handleSubmit = (event) => {
    event.preventDefault();
    const formData = new FormData();
    formData.append('selectedFile', new Blob([selectedFile], { type: 'image/jpg, image/png' }));
    // formData.append('uploadLink', uploadLink);

  

    const headers = {
      'Content-Type': 'image/jpg, image/png',
      Accept: 'application/vnd.vimeo.*+json;version=3.4',
    };

    try {
      axios
        .put(`${uploadLink}`, formData, {
          headers,
        })
        .then((response) => {
      
          console.log(`${uploadLink}link for upload`);
        });
    } catch (error) {
      console.log(error);
    }
  }; 
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