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

145
Vistas
Uploading file via Google Drive API with simple upload (uploadType=media)

I'm using google API and I want to download files from UI to my google drive.

As I found in google drive API documentation here, I want to use simple import.

For the moment I have such code for my onChange input event.

const onLoadFile = async (e: { target: { files: any } }) => {
  const fileData = e.target.files[0];

  //gapi request
  uploadFile(body);
  return null;
};

uploadFile:

const uploadFile = async (body: string) => {
  const result = await gapiRequest({
    path: `${ENDPOINT}/upload/drive/v3/files`,
    method: 'POST',
    body,
  });
  setUploadFileData(result);
};

gapiRequest:

const gapiRequest = async (options: gapi.client.RequestOptions): Promise<any> =>
  new Promise<any>((resolve, reject) =>
    gapi.client.request(options).execute((res) => {
        resolve(res);
        if (!res) {
        reject(res);
      }
  })
);

I need to know which request body I need to create for such a request.

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

0

The request body should consist of a form that contains both metadata and the file, like so:

const metadata = {
    "name": "yourFilename",
    "mimeType": "text/plain", // whatever is appropriate in your case
    "parents": ["folder id or 'root'"], // Google Drive folder id
};

const form = new FormData();
form.append('metadata', new Blob([JSON.stringify(metadata)], { type: 'application/json' }));
form.append('file', file); // file could be a blob or similar

You might also need to add an uploadType parameter to your path property. The multipart value works even for simple uploads.

See also here: https://stackoverflow.com/a/68595887/7821823

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