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

Facing issue in img upload when using uploadthing v4.x.x ++(using 7.3.0) #277

Open
20200015-anhh opened this issue Nov 28, 2024 · 0 comments

Comments

@20200015-anhh
Copy link

20200015-anhh commented Nov 28, 2024

Got Image Tool: uploading failed because of TypeError: Cannot read properties of undefined (reading 'reduce')
when im trying to upload an image.

my img:

image: {
                        class: ImageTool,
                        config: {
                            uploader: {
                                uploadByFile: async (file: File) => {
                                    console.log(file);

                                    // upload to uploadthing
                                    const [res] = await uploadFiles([file], 'imageUploader')
                                    console.log(res);
                                    return {
                                        success: 1,
                                        file: { url: res[0].fileUrl },
                                    };
                                },
                            },
                        }

my uploadFiles:

import type { OurFileRouter } from '~/app/api/uploadthing/core'
import {generateReactHelpers} from "@uploadthing/react";

export const { uploadFiles } = generateReactHelpers<OurFileRouter>();

my router:

import { createUploadthing, type FileRouter } from 'uploadthing/next-legacy'
import {currentUser} from "~/lib/auth";


const f = createUploadthing()

export const ourFileRouter = {
  imageUploader: f({ image: { maxFileSize: '4MB' } })
    .middleware(async (req) => {
        console.log(req)
      const user = await currentUser()
      if (!user) throw new Error('Unauthorized')
      return { userId: user.id }
    })
    .onUploadComplete(async ({ metadata, file }) => {console.log(file)}),
} satisfies FileRouter

export type OurFileRouter = typeof ourFileRouter

Can someone help me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant