diff --git a/packages/pieces/community/google-drive/package.json b/packages/pieces/community/google-drive/package.json
index a87f186be4f3..d084caf90843 100644
--- a/packages/pieces/community/google-drive/package.json
+++ b/packages/pieces/community/google-drive/package.json
@@ -1,6 +1,6 @@
{
"name": "@activepieces/piece-google-drive",
- "version": "0.7.9",
+ "version": "0.7.10",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
"dependencies": {
diff --git a/packages/pieces/community/google-drive/src/lib/action/create-new-text-file.ts b/packages/pieces/community/google-drive/src/lib/action/create-new-text-file.ts
index 8acffcd48bed..b18e5600d89d 100644
--- a/packages/pieces/community/google-drive/src/lib/action/create-new-text-file.ts
+++ b/packages/pieces/community/google-drive/src/lib/action/create-new-text-file.ts
@@ -1,11 +1,6 @@
import { createAction, Property } from '@activepieces/pieces-framework';
-import {
- httpClient,
- HttpMethod,
- AuthenticationType,
-} from '@activepieces/pieces-common';
-import FormData from 'form-data';
-import { googleDriveAuth, getAccessToken } from '../auth';
+import { drive as googleDrive } from '@googleapis/drive';
+import { googleDriveAuth, createGoogleClient } from '../auth';
import { common } from '../common';
import { createNewGdriveFileActionOutputSchema } from '../output-schemas';
@@ -31,12 +26,12 @@ export const googleDriveCreateNewTextFile = createAction({
displayName: 'Content type',
description: 'Select file type',
required: true,
- defaultValue: 'plain/text',
+ defaultValue: 'text/plain',
options: {
options: [
{
label: 'Text',
- value: 'plain/text',
+ value: 'text/plain',
},
{
label: 'CSV',
@@ -54,40 +49,32 @@ export const googleDriveCreateNewTextFile = createAction({
},
outputSchema: createNewGdriveFileActionOutputSchema,
async run(context) {
- const meta = {
- mimeType: context.propsValue.fileType,
- name: context.propsValue.fileName,
- ...(context.propsValue.parentFolder
- ? { parents: [context.propsValue.parentFolder] }
- : {}),
- };
+ const authClient = await createGoogleClient(context.auth);
+ const drive = googleDrive({ version: 'v3', auth: authClient });
- const metaBuffer = Buffer.from(JSON.stringify(meta), 'utf-8');
- const textBuffer = Buffer.from(context.propsValue.text!, 'utf-8');
+ // Normalize the legacy 'plain/text' value saved by existing flows to the
+ // valid 'text/plain' MIME type Google Drive expects.
+ const mimeType =
+ context.propsValue.fileType === 'plain/text'
+ ? 'text/plain'
+ : context.propsValue.fileType;
- const form = new FormData();
- form.append('Metadata', metaBuffer, { contentType: 'application/json' });
- form.append('Media', textBuffer, {
- contentType: context.propsValue.fileType,
- });
-
- const result = await httpClient.sendRequest({
- method: HttpMethod.POST,
- url: `https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart`,
- body: form,
- headers: {
- ...form.getHeaders(),
- },
- queryParams: {
- supportsAllDrives: String(context.propsValue.include_team_drives || false),
+ const response = await drive.files.create({
+ requestBody: {
+ name: context.propsValue.fileName,
+ mimeType,
+ ...(context.propsValue.parentFolder
+ ? { parents: [context.propsValue.parentFolder] }
+ : {}),
},
- authentication: {
- type: AuthenticationType.BEARER_TOKEN,
- token: await getAccessToken(context.auth),
+ media: {
+ mimeType,
+ body: context.propsValue.text,
},
+ supportsAllDrives: context.propsValue.include_team_drives ?? false,
+ fields: 'id, name, mimeType, kind',
});
- console.debug('File creation response', result);
- return result.body;
+ return response.data;
},
});
diff --git a/packages/pieces/community/google-drive/src/lib/action/upload-file.ts b/packages/pieces/community/google-drive/src/lib/action/upload-file.ts
index e3d75bb2359f..a277864a097e 100644
--- a/packages/pieces/community/google-drive/src/lib/action/upload-file.ts
+++ b/packages/pieces/community/google-drive/src/lib/action/upload-file.ts
@@ -1,12 +1,8 @@
import { createAction, Property } from '@activepieces/pieces-framework';
-import {
- httpClient,
- HttpMethod,
- AuthenticationType,
-} from '@activepieces/pieces-common';
-import FormData from 'form-data';
-import { googleDriveAuth, getAccessToken } from '../auth';
+import { Readable } from 'stream';
import mime from 'mime-types';
+import { drive as googleDrive } from '@googleapis/drive';
+import { googleDriveAuth, createGoogleClient } from '../auth';
import { common } from '../common';
import { uploadGdriveFileActionOutputSchema } from '../output-schemas';
@@ -34,43 +30,26 @@ export const googleDriveUploadFile = createAction({
outputSchema: uploadGdriveFileActionOutputSchema,
async run(context) {
const fileData = context.propsValue.file;
- const mimeType = mime.lookup(fileData.extension ? fileData.extension : '');
+ const mimeType = mime.lookup(fileData.extension ?? '') || 'application/octet-stream';
- const meta = {
- mimeType: mimeType,
- name: context.propsValue.fileName,
- ...(context.propsValue.parentFolder
- ? { parents: [context.propsValue.parentFolder] }
- : {}),
- };
+ const authClient = await createGoogleClient(context.auth);
+ const drive = googleDrive({ version: 'v3', auth: authClient });
- const metaBuffer = Buffer.from(JSON.stringify(meta), 'utf-8');
- const fileBuffer = Buffer.from(fileData.base64, 'base64');
-
- const form = new FormData();
- form.append('Metadata', metaBuffer, { contentType: 'application/json' });
- form.append('Media', fileBuffer);
-
- const result = await httpClient.sendRequest({
- method: HttpMethod.POST,
- url: `https://www.googleapis.com/upload/drive/v3/files`,
- queryParams: {
- uploadType: 'multipart',
- supportsAllDrives: String(
- context.propsValue.include_team_drives || false
- ),
- },
- body: form,
- headers: {
- ...form.getHeaders(),
+ const response = await drive.files.create({
+ requestBody: {
+ name: context.propsValue.fileName,
+ ...(context.propsValue.parentFolder
+ ? { parents: [context.propsValue.parentFolder] }
+ : {}),
},
- authentication: {
- type: AuthenticationType.BEARER_TOKEN,
- token: await getAccessToken(context.auth),
+ media: {
+ mimeType,
+ body: Readable.from(Buffer.from(fileData.base64, 'base64')),
},
+ supportsAllDrives: context.propsValue.include_team_drives ?? false,
+ fields: 'id, name, mimeType, kind',
});
- console.debug('File upload response', result);
- return result.body;
+ return response.data;
},
});
diff --git a/packages/web/src/app/builder/test-step/custom-test-step/test-webhook-dialog.tsx b/packages/web/src/app/builder/test-step/custom-test-step/test-webhook-dialog.tsx
index 85a06ab285d6..c75dc1014439 100644
--- a/packages/web/src/app/builder/test-step/custom-test-step/test-webhook-dialog.tsx
+++ b/packages/web/src/app/builder/test-step/custom-test-step/test-webhook-dialog.tsx
@@ -232,9 +232,7 @@ const TestWebhookFunctionalityForm = (
- field.onChange({ target: { value: record } })
- }
+ onChange={field.onChange}
disabled={false}
/>
@@ -252,9 +250,7 @@ const TestWebhookFunctionalityForm = (
- field.onChange({ target: { value: record } })
- }
+ onChange={field.onChange}
disabled={false}
/>