jeanbmar / payload-s3-upload

Send Payload CMS uploads to Amazon S3
MIT License
56 stars 9 forks source link

Not been able to upload #5

Closed outdatedx closed 2 years ago

outdatedx commented 2 years ago

Hey, So I had my s3 configured and I never change the config neither for payload nor s3 but someone how the plugin has stopped working yesterday I spent almost 4 hours and was not able to figure out why Im not able to upload,

PROBLEM: (TLDR) When I upload from my payload deploy its takes a while and never uploads it to the s3 folder.

I can add you to the repo cause I don't want to make things public and leaks something.

jeanbmar commented 2 years ago

Hello @outdatedx, can you please provide:

outdatedx commented 2 years ago

Hello @outdatedx, can you please provide:

  • The versions of Payload and this plugin you are using

  • Some error logs or, better, a minimal reproducible example

Hey, @jeanbmar So I'm using Payload version 0.18.1

And that's the thing there are no logs, when I upload the upload is successful but never shows up on my s3 bucket.

outdatedx commented 2 years ago

Hello @outdatedx, can you please provide:

  • The versions of Payload and this plugin you are using
  • Some error logs or, better, a minimal reproducible example

Hey, @jeanbmar So I'm using Payload version 0.18.1

And that's the thing there are no logs, when I upload the upload is successful but never shows up on my s3 bucket.

This is something I was able to get from the logs when I uploaded

// 2022-07-12T09:29:24.612648+00:00 heroku[router]: at=info method=POST path="/api/media?locale=en&depth=0&fallback-locale=null" host=my-backendd.herokuapp.com request_id=705efc3e-eeed-4ae0-b92b-75bc09a65ca8 fwd="103.225.134.33" dyno=web.1 connect=0ms service=26998ms status=201 bytes=1307 protocol=https
// 2022-07-12T09:29:25.280046+00:00 heroku[router]: at=info method=GET path="/api/media/62cd3ef4c6856e6aa0798184?locale=en&fallback-locale=null&depth=0&draft=true" host=my-backendd.herokuapp.com request_id=384dbe24-5528-4cd9-b7d6-27d89b5c8440 fwd="103.225.134.33" dyno=web.1 connect=0ms service=257ms status=200 bytes=1230 protocol=https
// 2022-07-12T09:29:26.599479+00:00 heroku[router]: at=info method=GET path="/media/wallpapernew-1024x576.png" host=my-backendd.herokuapp.com request_id=81222c58-0db1-4792-ae10-87b178c3d30b fwd="103.225.134.33" dyno=web.1 connect=0ms service=128ms status=404 bytes=620 protocol=https
// 2022-07-12T09:29:25.992748+00:00 heroku[router]: at=info method=GET path="/api/media?where%5Band%5D%5B0%5D%5Bor%5D%5B0%5D%5B_status%5D%5Bequals%5D=published&where%5Band%5D%5B0%5D%5Bor%5D%5B1%5D%5B_status%5D%5Bexists%5D=false&where%5Band%5D%5B1%5D%5Bid%5D%5Bequals%5D=62cd3ef4c6856e6aa0798184&depth=0" host=my-backendd.herokuapp.com request_id=015cccc2-e036-4e0a-bee1-ecb1abd15ddf fwd="103.225.134.33" dyno=web.1 connect=0ms service=255ms status=200 bytes=1380 protocol=https
outdatedx commented 2 years ago

// Media.ts

import { CollectionConfig } from 'payload/types';
export type MediaType = {
  filename: string;
  width: number;
  height: number;
  alt: string;
  url: string;
  sizes: {
    card?: {
      filename: string;
      width: number;
      height: number;
    };
    feature?: {
      filename: string;
      width: number;
      height: number;
      url: string;
    };
  };
};

const Media: CollectionConfig = {
  slug: 'media',
  labels: {
    singular: 'Media',
    plural: 'Media',
  },
  access: {
    read: (): boolean => true, // Everyone can read Media
  },
  upload: {
    staticDir: 'media',
    staticURL: '/media',
    disableLocalStorage: true,
    // s3: {
    //   bucket: process.env.AWS_BUCKET_NAME,
    //   prefix: 'fabricstudio/assets',
    //   commandInput: {
    //     ACL: 'public-read',
    //   },
    // },
    imageSizes: [
      {
        name: 'card',
        width: 640,
        height: 480,
        crop: 'center',
      },
      {
        name: 'feature',
        width: 1024,
        height: 576,
        crop: 'center',
      },
    ],
    adminThumbnail: 'feature',
    mimeTypes: ['image/*'],
  },
  hooks: {
    afterRead: [
      ({ doc }) => {
        doc.url = `https://${process.env.AMAZONWS_BUCKET_NAME}.s3.${process.env.AMAZON_WS_REGION}.amazonaws.com/outdated/assets/${doc.filename}`;
        Object.keys(doc.sizes).forEach(
          (k) =>
            (doc.sizes[
              k
            ].url = `https://${process.env.AMAZONWS_BUCKET_NAME}.s3.${process.env.AMAZON_WS_REGION}.amazonaws.com/outdated/assets/${doc.sizes[k].filename}`)
        );
      },
    ],
  },
  fields: [
    {
      name: 'alt',
      label: 'Alt Text',
      type: 'text',
      required: true,
    },
    {
      name: 'url',
      type: 'text',
      access: {
        create: () => false,
      },
      admin: {
        disabled: true,
      },
      hooks: {
        afterRead: [
          ({ data: doc }) =>
            `https://${process.env.AMAZONWS_BUCKET_NAME}.s3.${process.env.AMAZON_WS_REGION}.amazonaws.com/outdated/assets/${doc.filename}`,
        ],
      },
    },
  ],
};

export default Media;
jeanbmar commented 2 years ago

The s3 key in the upload collection is commented. Have you applied the idea from https://github.com/jeanbmar/payload-s3-upload/issues/3? Because what jmikrut suggests is not how this plugin works. The collection-related config cannot be passed in plugin init, and I'm strongly against it. It's just bad to manage some collection config at 2 different places.

If you want to get rid of the TS warning, you need to define a custom CollectionConfig type that will allow the s3 key in the upload property.

outdatedx commented 2 years ago

The s3 key in the upload collection is commented. Have you applied the idea from #3? Because what jmikrut suggests is not how this plugin works. The collection-related config cannot be passed in plugin init, and I'm strongly against it. It's just bad to manage some collection config at 2 different places.

If you want to get rid of the TS warning, you need to define a custom CollectionConfig type that will allow the s3 key in the upload property. Right that does make sense.

I did try to do it thats why is actually commented out cause I do pass the options in the config but the as you said I have to define a type so I did try to extend the CollectionConfig but it didnt work if you can help me with it that would be great

outdatedx commented 2 years ago

Well I think I figured it out thanks.