Next.js Discord

Discord Forum

Having trouble uploading files please help

Unanswered
Common House-Martin posted this in #help-forum
Open in Discord
Common House-MartinOP
This is how I'm sending the file, i needed a controlled way

function handleAddFile(e: any) { e.preventDefault() const fdata = new FormData() fdata.append("filecache", e.currentTarget.files[0]) subirArchivoCache(fdata).then(res => { setFile(res) }) }

this is the server action in question

"use server" import { env } from "@/lib/env" import { minioClient } from "@/lib/minio" export default async function subirArchivoCache(formData: FormData) { console.log('subiendo archivo...') const file = formData.get("filecache") as File | null if (file) { const bucket = env.R2_CACHE_BUCKET; const exists = await minioClient.bucketExists(bucket) if (exists) { console.log('Bucket ' + bucket + ' exist.') } else { await minioClient.makeBucket(bucket) console.log('Bucket ' + bucket + ' created.') } await minioClient.putObject(env.R2_CACHE_BUCKET, file.name, file.stream()) // return file[0].name return file.name } return "error" }

now minio client is giving me the following error I know it says its the wrong type of object but why if in the frontend is a FileList which I get the first File. If i send the FileList inside the form data then i get object object as string and it's even worse.

TypeError: third argument should be of type "stream.Readable" or "Buffer" or "string" at Client.putObject (C:\node\gtp-next\.next\server\chunks\ssr\node_modules_minio_dist_esm_936ba8._.js:3288:19) at Client.putObject (C:\node\gtp-next\.next\server\chunks\ssr\node_modules_minio_dist_esm_936ba8._.js:856:19) at subirArchivoCache (C:\node\gtp-next\.next\server\chunks\ssr\[root of the server]__7a31b7._.js:2045:146)

2 Replies

Common House-MartinOP
hello?
anyone? please?