chladog / payload-webp

payloadcms/payload plugin for automatic image conversion to webp format.
https://www.npmjs.com/package/payload-webp
GNU General Public License v3.0
44 stars 5 forks source link

Support for payloadcms/plugin-cloud-storage #4

Closed matthijs166 closed 2 years ago

matthijs166 commented 2 years ago

Im deploying payload in the cloud via digital ocean app service.

When I use your plugin and im building my app again all the generated webp files are gone. Im using the S3 adapter so that the files are uploaded and used on digital ocean spaces.

Is it easy to import the plugin adapter here and upload it to storage via the adapter. Or that we need to pass the adapter in the webp config. So that it can be uploaded. https://github.com/chladog/payload-webp/blob/main/src/Plugin.ts#L194

Its to bad that I cant use your plugin in production at the moment :(

chladog commented 2 years ago

Hello @matthijs166, I followed the way the official upload functionality is implemented in payload. Basically the behavior is mirrored from payload/uploadFile.

When using external provider, the responsibility of storing the files lies on your adapter. I believe your will be easily able to extend its current functionality.

To allow you that I have released a new version that will pass along buffer data of each image size to express req object the same way it is done by payload.

Here is a new excerpt from readme:

Buffer objects

You can access buffer objects of processed image and all image sizes from Express request object req.payloadWebp. This way your adapter can store the files with external provider for an instance. The maximum resolution webp buffer is at req.payloadWebp.src, other image sizes are at their respective name req.payloadWebp[imageSizeName].

jack1913 commented 1 year ago

Hi @chladog,

I am trying to use buffer objects, but none of the payloads hooks are returning it. :/ If I understand correctly the flow goes like this.

  1. ACTION - Upload image via Payload.
  2. BEFORE-CHANGE, operation create - plugin-cloud-storage does its magic.
  3. AFTER-CHANGE, operation create - your plugin
  4. BEFORE(AFTER)-CHANGE, operation update - I think that's where we should be able to access buffer object, so we could perform plugin-cloud-storage operation. I know that we need to modify said plugin. But that's not the point at this moment.

For now I didn't have time to analyze your code, but I think that there might be some small err that you are not appending this obj to the express response.

If you don't have enough time to address this, just point me where to look and I can create a PR with the fix.

Thanks,