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

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

Open
mohamed-abd-elkahlk opened this issue Feb 26, 2024 · 2 comments
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@mohamed-abd-elkahlk
Copy link

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

@mohamed-abd-elkahlk mohamed-abd-elkahlk added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Feb 26, 2024
@tumetus
Copy link

tumetus commented Apr 8, 2024

I'm facing this same issue.

Is there currently a way to upload files with Next.js 14+ or do we need to wait for this to be fixed? Any timeline for the fix? Thanks!

@KenzieFu
Copy link

KenzieFu commented May 7, 2024

Hi, so recently I also having this kind of issue while uploading my images to the Google Cloud storage with the help of multer and storing it to memory storage before uploading to the cloud.

I figured out that the keyFile that we are trying to store is a json object, but the keyFile attribute only wants a path to the key.json
image
image

I hope this gonna solves your issues. I'm sorry because my English is not that good :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

4 participants