payloadcms / payload

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
https://payloadcms.com
MIT License
24.45k stars 1.55k forks source link

MimeType & CSV Upload Issue #8736

Open ythoumaOfficial opened 1 day ago

ythoumaOfficial commented 1 day ago

Describe the Bug

I'm generating CSV file and than uploading it to the media library using the code below: the same code is working with pdf and image extensions but with CSV the record is not saving the MIME TYPE and the file is not uploaded. I'm using @payloadcms/storage-s3 to upload to my S3.

to be more clear:

  1. on uploading PDF/image/video: 1.1. the file uploaded to s3 1.2. a record with the right mimeType

  2. on uploading csv file from the code below 2.1 the file is not uploaded to S3 2.2. a record is added to the media collection but with null in mimeType field

  3. on uploading the same generated file from the admin panel into the media libraray, it's added and uploaded

Reproduction Steps

generate a csv file and try to add to media libarary:

      const csvFilePath = generateCSVfile()
      const csvMedia = await req.payload.create({
        collection: 'media',
        data: {
          alt: 'generated csv',
          // mimeType: 'text/csv',
        },
        filePath: csvFilePath,
        req,
      })

Which area(s) are affected? (Select all that apply)

plugin: cloud-storage, db-postgres

Environment Info

Binaries: Node: 20.12.2 npm: N/A Yarn: N/A pnpm: N/A Relevant Packages: payload: 3.0.0-beta.96 next: 15.0.0-canary.104 @payloadcms/db-mongodb: 3.0.0-beta.96 @payloadcms/db-postgres: 3.0.0-beta.96 @payloadcms/email-nodemailer: 3.0.0-beta.96 @payloadcms/graphql: 3.0.0-beta.96 @payloadcms/live-preview: 3.0.0-beta.96 @payloadcms/live-preview-react: 3.0.0-beta.96 @payloadcms/next/utilities: 3.0.0-beta.96 @payloadcms/plugin-cloud: 3.0.0-beta.96 @payloadcms/plugin-cloud-storage: 3.0.0-beta.96 @payloadcms/plugin-form-builder: 3.0.0-beta.96 @payloadcms/plugin-nested-docs: 3.0.0-beta.96 @payloadcms/plugin-redirects: 3.0.0-beta.96 @payloadcms/plugin-search: 3.0.0-beta.96 @payloadcms/plugin-seo: 3.0.0-beta.96 @payloadcms/richtext-lexical: 3.0.0-beta.96 @payloadcms/storage-s3: 3.0.0-beta.96 @payloadcms/translations: 3.0.0-beta.96 @payloadcms/ui/shared: 3.0.0-beta.96 react: 19.0.0-rc-06d0b89e-20240801 react-dom: 19.0.0-rc-06d0b89e-20240801 Operating System: Platform: win32 Arch: x64 Version: Windows 11 Home Available memory (MB): 12102 Available CPU cores: 8

JarrodMFlesch commented 1 day ago

@ythoumaOfficial The example you gave is so minimal it will be hard to reproduce. If you would like to add more information, ie, the function code for both the working example and the non-working example that would be great! Otherwise we will likely close this issue.

A reproduction would be ideal in this situation. Something we can spin up and reach the error quickly.

akhrarovsaid commented 1 day ago

Yeah, just piggy-backing off Jarrod's answer here:

I just tried to reproduce your issue using the monorepo - no luck. My CSV files upload correctly and are saved with the appropriate mimetype. I also noticed that you are generating your own CSV files. I'd double check to make sure your generation function works as expected. You may also consider updating your Payload version as it seems you're on beta.96 while the latest is beta.114 beta.115 (Read the releases tab for breaking changes if you do this).