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