Extending File Upload


(Roderick McTainsh) #1

Hi All,

Would it be feasible to create a plugin for Discourse that allows an external system to be notified in real time when a file is uploaded, as opposed to having to use the API to periodically crawl the uploaded files - assuming that is possible?

This webhooks plugin looks really handy - Webhooks plugin - but I can’t see any file upload related events to hook into. Would they be something that is likely to be implemented or am I looking in the wrong place (uploads_controller.rb).



(Khoa Nguyen) #2

@eviltrout once said that he would add more hooks for you if you have a right point

(Jens Maier) #3

The best place to add a hook would probably be in Upload::create_for (in app/models/upload.rb). It’s a pretty straight-forward method, so you could just monkey-patch it until a proper event is built in.

However, note that this will also trigger on trivial things such as pasted images and whenever hotlinked images are pulled down…

(Roderick McTainsh) #4

Fantastic, thanks for the tip!