'return file id after resumable upload finished with google drive
I'm integrating google drive API in my application and I'm using resumable upload approach but i can't figure out how can i get file id after upload finished in the resumable response body
here is my code to get resumable uri
const body = JSON.stringify({
name:file.originalname,
mimeType:file.mimetype,
parents:[parent folder id]
})
const url = 'https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable'
const option = {
method: 'post',
body,
headers: {
Authorization: `Bearer ${access_token}`,
'Content-Type': 'application/json; charset=UTF-8',
}
}
const response = await fetch(url, option)
const resumableURI = response.headers.get('location')
and this is my code to upload my file chunks
const options = {
method: 'PUT',
headers: {
'Content-Length': file.size,
'Content-Range': `bytes ${start}-${end - 1}/${length}`,
},
body: file.buffer, // contents of the chunk
};
const response = await fetch(RESUBMALEURI, options)
this is the response i got from api after upload complete
response: Response {
size: 0,
timeout: 0,
[Symbol(Body internals)]: { body: [PassThrough], disturbed: false, error: null },
[Symbol(Response internals)]: {
url: 'https://www.googleapis.com/upload/drive/v3/files?
uploadType=resumable&upload_id=ADPycdvajyaSOgYUjPmFgZIbi-
vbjM0U7xHe0yLy1eahXOC1Zq06K7ZFN2O0c_IKRdEJfa-WFc8DwE814cjV0nhCv0U',
status: 200,
statusText: 'OK',
headers: [Headers],
counter: 0
}
}
}
is there any option i can add to request of resubmale uri or upload request itself to return the file id in the end
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
