TypeError [ERR_INVALID_ARG_TYPE]: The "paths[0]" argument must be of type string. Received an instance of Object

Open
#3,442 3 comments 5 reactions 1 assignee View on GitHub

Maintainers usually reply within 2 days

@sofisl is already working on this.

Since Feb 26, 2024.

Assessment

This issue has not been assessed yet.

Description

priority: p2 type: bug

hi i got this error
"TypeError [ERR_INVALID_ARG_TYPE]: The "paths[0]" argument must be of type string. Received an instance of Object"
every time i try to upload a file to my drive account and here is the code

"use server";
import { google } from "googleapis";
import * as fs from "fs";
import { join } from "path";
export async function addFile(e: FormData) {
  const file: File | null = e.get("file") as unknown as File;

  const bytes = await file?.arrayBuffer();
  const buffer = Buffer.from(bytes);

  const path = join("/", "/tmp", file.name.trim());
  fs.writeFileSync(path, buffer);

  const keyFile = await JSON.parse(
    fs.readFileSync(process.cwd() + `/src/app/key.json`, "utf-8")
  );

  const auth = new google.auth.GoogleAuth({
    keyFile,
    scopes: ["https://www.googleapis.com/auth/drive"],
  });
  const drive = google.drive({
    version: "v3",
    auth,
  });

  const response = () => {
    return new Promise((resolve, reject) => {
      drive.files.create(
        {
          requestBody: {
            name: file.name,
            parents: ["1TebOIirZf_P9xb2Vc2fAVhdMrTU_rN-U"],
          },
          media: {
            body: fs.createReadStream(path),
            mimeType: file.type.toString(),
          },
          fields: "id",
        },
        function (err, file) {
          if (err) {
            reject(err);
          }
          resolve(file);
        }
      );
    });
  };

  await response().catch((err) => console.log(err));
}

so could any one help with that or have a tip for solve this problem
i use next.js 14.1.0 as a javascript frame work node with version 20.9.0

Dominant language
TypeScript
Stars
12.3k
Forks
2k
Avg merge
3d 10h
Merged PRs (30d)
9

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from googleapis/google-api-nodejs-client

All issues in googleapis/google-api-nodejs-client

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.