mheiden
I'm new here

Modifying uploads

Hi!

Is it possible to modify an while while it is uploaded?

Our use-case: Adobe Illustrator creates awful SVGs. We would like to clean them up, while getting uploaded to save our authors from manual steps which are quite error-prone.

I tried to implement an UploadFilter, but I receive an Exception that the size of the uploaded data changed. (Which is obviously what I want...)

Is there another approach to modify files while they are uploaded?

Best regards,

  Martin Heiden

PS: We are using fs5.2

3 Replies
philippr
Returning Spectator

Hi Martin,

you can use an upload hook (de.espirit.firstspirit.service.mediamanagement.UploadHook):

Or a a StoreListener might help (de.espirit.firstspirit.access.store.StoreListener).

Regards,

Philipp

Hi Philipp,

you mean by modifying the File that I get when

public void preProcess(@NotNull final BaseContext baseContext, @NotNull final Media media, @NotNull final File file, @NotNull final InputStream inputStream, final long length) throws UploadRejectedException, IOException {
    }

is called?

I didn't find and example in the documententation which describes the modification of medias, all the parameters are declared as final and the method is void... That didn't seem to be intended for modification. I know that only the reference to the "final File" is immutable.

I would expect that the api has a method with a return value when someone shall be able to change something.

I'll give it a try.

Thanks,

  Martin.

0 Kudos

Okay, solved it. But it is quite ugly.

I used the postProcess-Method, but I had to keep a static Reference to the Media I worked on to prevent a StackOverflow. The UploadHook was triggered again when I called setFile on the File-Argument.