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({
        parents:[parent folder id]

    const url = ''
    const option = {
        method: 'post',
        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: ' 
    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


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

When I saw your script and your additional response value, I’m worried that you might have retrieved the response value using console.log(response) from const response = await fetch(RESUBMALEURI, options). If my understanding is correct, in that case, unfortunately, such a response is obtained.

If your script for the resumable upload the file works fine and the upload is completely finished, how about the following modification?


const response  = await fetch(RESUBMALEURI, options)


const response  = await fetch(RESUBMALEURI, options)
const res = await response.json();
// console.log(; // If you want to retrieve only the file ID, you can use this.
  • By this modification, when at the last request, you can obtain the following value.
        kind: 'drive#file',
        id: '###',
        name: '###',
        mimeType: '###'


  • By the way, in your 1st request, the location is put in the variable of resumableURI. But in your script for uploading the file content, you are using the RESUBMALEURI as the endpoint. If your actual situation uses this, please modify this. Please be careful about this.


All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x