Single Page App and leveraging Kentico's Media Library

Yang Wen asked on October 21, 2016 21:30

I'm creating a Dashboard SPA in with AngularJS. The page will be hosted in Kentico.

There is a need to allow user to upload attachments to associate with data records displayed in the SPA. I've already ruled out uploading files via the REST service due to the need of Base64 encoding the binary.

My plan is to implementing the SPA markup in a page's layout. The markup will include a webpartzone element which will allow dropping in the media file uploader webpart.

It looks like the direct path to an uploaded file can be derived via the pattern:

<media library base URL>/<Library name>/<file name>

On a test page, I have enabled the updatepanel flag on the media uploader webpart to prevent a full POST back. All seems to work on a test page, except I don't know what/if any event there is to subscribe for the successful upload. I need to subscribe to the file uploader's event to store a reference to the attachment.

Any suggestions?

Recent Answers


Jan Hermann answered on October 22, 2016 11:14

if you have the FileGUID available the easiest way to build the url is following:

/getmedia/<FileGUID>/<name, filename or anything else including random string or nothing at all>

0 votesVote for this answer Mark as a Correct answer

Yang Wen answered on October 23, 2016 14:43

Thanks Jan, the other issue is how to be notified once the upload is successful. Is there an event that gets triggered upon successful upload of the file? I can only persist the attachment URL after successful upload.

1 votesVote for this answer Mark as a Correct answer

Zachary Perry answered on October 24, 2016 16:18

This might help you with the events. You would use something like:

MediaLibraryInfo.TYPEINFO.Events.Insert.After +=
1 votesVote for this answer Mark as a Correct answer

Yang Wen answered on October 24, 2016 16:37 (last edited on October 24, 2016 16:38)

Thanks Zachary.

I was referring to client-side events. In the context of doing the upload in a SPA angular app. My client side app needs to be notified when the upload was successful so I can persist the attachment URL via the SPA app. Can't use server-side events handlers since Kentico is not inherently aware of association of an attachment with a data record in my custom table.

0 votesVote for this answer Mark as a Correct answer

Ajay Kumar answered on September 30, 2017 21:40

Like Jan said if you have FileUGID available /getmedia/< FileGUID >/ it will be the easiest. This guide here will help you with understanding the events https://docs.kentico.com/display/K9/Handling+object+events

Tutuapp | ShowBox

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.