Reputation: 4522
I'm unable to rename files in Google Drive in a NodeJs app. I'm using:
20.1.0
.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?
Upvotes: 0
Views: 201
Reputation: 22286
Try setting your new name in params.media.body
, eg
params.resource = {name: "newname"}
corrected as per comment
Upvotes: 1