Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drive_v3 files.create unable to get resumable session URI #3426

Open
riccardomartinelli opened this issue Jan 22, 2024 · 1 comment
Open
Labels
api: drive Issues related to the Drive API API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@riccardomartinelli
Copy link

riccardomartinelli commented Jan 22, 2024

Feature

I think that would be nice to be able to get the resumable session URI by specifying the uploadType: 'resumable' parameters on the drive_v3 files.create method, instead of doing a POST request.

const params = {
  uploadType: 'resumable'
};

const options = {};

const res = await drive.files.create(params, options);
const uri = res.headers.location;

Motivation

Initially I thought that was the case by reading the documentation on how to perform a resumable upload (link).
So I take a look at the code to understand how to do that but unfortunately it seems impossible.

To summarise the documentation to get a resumable URI we need to do a POST like so:
POST https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable

If we take a look at how the create method it's implemented we found out that we have this URI in to the mediaUrl attribute. (link)

If we take a look how the request it's constructed we found out that only when we have the media.body the correct url it's used. But then the uploadType it's changed in to something else. So the POST request can't be constructed as desired. (link)

Solution

In this case a first simple fix would be modify the createAPIRequestAsync of googleapis-common to add another if statement to enforce the right URI when we have an empty body and the uploadType is set to "resumable". Pretty much like so:

if (parameters.mediaUrl && media.body) {
  options.url = parameters.mediaUrl;
  if (resource) {
    params.uploadType = 'multipart';
    // more code
  } else {
    params.uploadType = 'media';
    // more code
  }
} else if (parameters.mediaUrl && params.uploadType === 'resumable') {
  options.url = parameters.mediaUrl;
} else {
  options.data = resource || undefined;
}

The current solution that I could find instead is to override the URI in the options like so:

 const options = {
  rootUrl: 'https://www.googleapis.com/upload'
};

Please let me know if i'm missing something or if I should proceed with a pull request on nodejs-googleapis-common repository.

@riccardomartinelli riccardomartinelli added priority: p3 Desirable enhancement or fix. May not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. labels Jan 22, 2024
@product-auto-label product-auto-label bot added the api: drive Issues related to the Drive API API. label Jan 22, 2024
@MrSaints
Copy link

I've encountered the exact same issue, the workaround to override the URI works for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: drive Issues related to the Drive API API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

2 participants