0

I create my API using v3 of Drive Api and usign uploadType=resumable, the server return me status code 200 and the metadata for the file, but when I see in drive, the file isn't there

// Client


googleClientRequest() {
    const keysEnvVar = process.env["CREDS"];
    if (!keysEnvVar) {
      throw new Error("The $CREDS environment variable was not found!");
    }

    const keys = JSON.parse(keysEnvVar);

    return new GoogleAuth({
      scopes: [
        "https://www.googleapis.com/auth/drive",
        "https://www.googleapis.com/auth/drive.file",
      ],
      credentials: keys,
});

// Initial request

const initialFile = await client.request({
        url:
          "https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable",
        method: "POST",
        headers: {
          "Content-Type": "application/json; charset=UTF-8",
          Accept: "application/json",
        },
        data: {
          name: `${job.data.callId}.mp3`,
        },
});

// File upload

async doUpload(fileLink: string, driveLink: string) {
    const client = this.googleClientRequest();

    const { data, headers } = await axios({ // The file comes from zoom api is a recorder
      method: "GET",
      url: fileLink,
      responseType: "arraybuffer",
    });

    const response = await client.request({
      url: driveLink,
      headers: {
        "Content-Type": "application/json; charset=UTF-8",
        "X-Upload-Content-Type": "audio/mp3",
        "X-Upload-Content-Length": headers["zoom-file-size"],
      },
      method: "POST",
      data: Buffer.from(data),
    });

    console.log(response.status, response.data, response.statusText);
    return response;
}

// The response

200 OK 
{
  kind: 'drive#file',
  id: '######',
  name: '1e9af0f9-9d3e-4287-a9fa-7cb3d229c1ad.mp3',
  mimeType: 'audio/mp3'
}

I try everything, I try with this example Angular 2+ HTTP POST and GDrive API. Resumable file upload with name

  • I cannot understand the relationship between "// Initial request" and "// File upload". Can I ask you about the detail of it? – Tanaike Jul 05 '22 at 23:06
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jul 06 '22 at 09:04

0 Answers0