Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Forms & Blueprints

Image upload with preprocessing

plugins

Solved by Stefan Jäger View solution

Started by Stefan Jäger 5 years ago · 2 replies · 912 views
5 years ago

Hey guys,

I am trying to create a new form field based on the file upload field. My goal is to do some image preprocessing on the temporary image file before uploading it to the destination folder.

Do you have any hints how I get the temporary image file path after the upload via dropzone finishes? Are there events to hook into?

Is there any kind of documentation regarding the Grav Dropzone?

Edit: Found out Grav uses Dropzone,js (https://www.dropzonejs.com/)

last edited 04/01/21 by Stefan Jäger
5 years ago

@stepbyweb, You could create a plugin and subscribe to event onFormProcessed.

In that event, you can fetch the values submitted by the form. Never tried your specific use-case though...

👍 1
5 years ago Solution

Right now my solution is a pure JavaScript one.

I also decided to do pre-upload manipulation.

You can get the Dropzone object from Grav's file field or the pagemedia field (which I switched to) and intercept the image upload with the Dropzone's "transformFile" hook.

At this point I can manipulate the dropped image and return it to Grav for uploading.

👍 1
last edited 04/12/21 by Stefan Jäger

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by Ton Haarmans, 5 years ago
13 1140 4 months ago
Forms & Blueprints · by Hugo Oliveira, 5 months ago
0 63 5 months ago
Forms & Blueprints · by Flachy Joe, 6 months ago
9 138 6 months ago
Forms & Blueprints · by Augustus, 7 months ago
7 114 7 months ago
Forms & Blueprints · by Julien, 7 months ago
10 132 7 months ago