Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

88
Visualizações
how to retrieve text from google drive documents

I am using react-google-drive-picker to select a file from GDrive in my NextJS app. Once I have picked a file and retrieved the meta information, what is the suggested way to download or just retrieve the file content? What API is suggested to use authResponse to authenticate?

I am using:

useEffect(() => {
 // do anything with the selected/uploaded files
 if (data) {
    var file = data.docs[0]
    var xhr = new XMLHttpRequest();
    xhr.open('GET', file['url']);
    xhr.setRequestHeader('Authorization', 'Bearer ' + authResponse['access_token']);
    xhr.setRequestHeader('Content-Type', 'application/vnd.google-apps.document');
    xhr.onload = function () {
        var content = xhr.responseText
        console.log(content)
    };
    xhr.onerror = function () {
        console.log("ERROR LOADING THE FILE")
    };
    xhr.send(JSON.stringify({"alt" : "media"}));
 }
}, [data])

but the text of the document is not present in the response...

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

following the suggestion by @Gonzalo-Matheu, here's a way to obtain the text after picking a file with react-google-drive-picker in nextjs:

var file = data.docs[0]
var xhr = new XMLHttpRequest();
var url = 'https://www.googleapis.com/drive/v3/files/' + file['id'] + '/export?mimeType=text%2Fplain&key=' + process.env.NEXT_PUBLIC_GOOGLE_API_KEY
xhr.open('GET', URL);
xhr.setRequestHeader('Authorization', 'Bearer ' + authResponse['access_token']);
xhr.onload = function () {
 var value = xhr.responseText
 // do what you need with file content
 console.log(value)
};
xhr.onerror = function () {
  console.log("ERROR LOADING THE FILE")
};
xhr.send();
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda