Google-api-nodejs-client: Can't rename Drive Files with NodeJS library

Created on 17 Jul 2017  路  1Comment  路  Source: googleapis/google-api-nodejs-client

_From @ghego1 on July 16, 2017 15:54_

It seems it is impossible to rename files in Google Drive in a NodeJs app.

I'm using:

  • googleapi nodeJs library v. 20.1.0.
  • node v. 8.1.4

The app is handling requests for files fine, and it is able to duplicate files. However, when updating them, the new name is never applied.

I do get as a response the file resource, which would entail that the request was successful.

I'm doing this:

const google = require( 'googleapis' );
let googleService = google.drive( 'v3' );

let params = {
  auth: testedAndValidOAuth,
  fileId: validFileId,
  uploadType: 'multipart',
  name: "some name 2"
};

googleService.files.update( params, ( err, response ) => console.log(response));

For the property uploadType I've tried with and without it, with all the available options: resumable, multipart, and media. When trying media I got the following error:

Error: The API returned an error: Error: Uploads must be sent to the upload URL. Re-send this request to https://www.googleapis.com/upload/drive/v3/files/xxxfileIdxxx?uploadType=media&name=some+name+2

I've tried to edit manually the link in the library and the error went away, but unfortunately the name did not change.

Looking in the library I've noticed that the name param is not mentioned:

@param {object} params Parameters for request
@param {string=} params.addParents A comma-separated list of parent IDs to add.
@param {string} params.fileId The ID of the file.
@param {boolean=} params.keepRevisionForever Whether to set the 'keepForever' field in the new head revision. This is only applicable to files with binary content in Drive.
@param {string=} params.ocrLanguage A language hint for OCR processing during image import (ISO 639-1 code).
@param {string=} params.removeParents A comma-separated list of parent IDs to remove.
@param {boolean=} params.supportsTeamDrives Whether the requesting application supports Team Drives.
@param {boolean=} params.useContentAsIndexableText Whether to use the uploaded content as indexable text.
@param  {object} params.resource Media resource metadata
@param {object} params.media Media object
@param {string} params.media.mimeType Media mime-type
@param {string|object} params.media.body Media body contents
@param {object} [options] Optionally override request options, such as `url`, `method`, and `encoding`.
@param {callback} callback The callback that handles the response.

So I'm wondering, am I doing something wrong, is this intended, meaning that we can't edit file names, or is it a bug in the library?

I've also opened a StackOverflow question here.

_Copied from original issue: googleapis/googleapis#404_

Most helpful comment

_From @ghego1 on July 17, 2017 12:51_

Turns out it has to be set via

params.resource = { name: "newname"}

The docs are not perfectly clear on this, perhaps it would be worth mentioning it.

>All comments

_From @ghego1 on July 17, 2017 12:51_

Turns out it has to be set via

params.resource = { name: "newname"}

The docs are not perfectly clear on this, perhaps it would be worth mentioning it.

Was this page helpful?
0 / 5 - 0 ratings