Best practise for storing and displaying files on website

Srikrishna Podduturi asked on May 2, 2019 10:10

Hi Team,

I am new to Kentico and working on Kentico 12. Our website consists of large number of products and each product will consist of different files (images, videos etc). The required files for these will be updated in a docs server.

I will be able to synchronize the files to the server in which the website is hosted. Could you please suggest me the best practise for displaying these files on my website? I have read the documentation that media libraries can be used for this, But the files will be added in a regular basis.

Thanks in advance.

Correct Answer

Dmitry Bastron answered on May 2, 2019 10:37

Hi Srikrishna,

The best practice would be to sync Media files in the Media Library using Kentico Integration bus. You can read about it here and here. Working with media library files would be much better then (for example you can easily resize images via ?width=X&height=Y URL parameters).

So, in your example if you have physical files synchronized to some folder on webserver you can write the code of connector which will import new media files into the Media Library and display this media on the site from Media Library.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Srikrishna Podduturi answered on May 2, 2019 12:08 (last edited on May 2, 2019 12:12)

Thanks Dmitry Bastron :)

After synchronizing using Kentico integration bus, I will have to programmatically upload files to media libraries using Kentico API so that it registers in database, Is this correct?

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on May 2, 2019 12:30

Almost. Uploading files to the Kentico media library using Kentico API should happen not after but should be a part of integration bus implementation. For example, you can have external service or Kentico Scheduled Task which will call ProcessExternalTask with new file to sync into the Media Library and then in PrepareInternalObject you create MediaFileInfo object based on the physical file and Kentico then will import it in the Media Library for you. Please read carefully this article.

0 votesVote for this answer Mark as a Correct answer

Srikrishna Podduturi answered on May 7, 2019 10:44

Hi Dmitry Bastron,

Is there any way to get all the unregistered media files of a media library and then register them to database using Kentico API?

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on May 7, 2019 12:20

Hi Srikrishna Podduturi,

No, not to my knowledge. In Kentico decompiled dlls I've seen that they are checking on a folder basis. For example, if there is a media library folder /library1/folder1/folder2 Kentico gets all the physical files by this path and checks if they are existing in the database (table Media_File, column FilePath). If not, Kentico shows these files as available to be imported.

It might be hard to replicate this logic for entire library as it might be performing slow (especially if you're going to use Azure or Amazon storage for media files). Instead, you can introduce some sort of "Import" folder: drop the files to import in this folder and Kentico task will check and import those files into the library and remove from "Import" folder in case of success. I would have done it this way.

0 votesVote for this answer Mark as a Correct answer

Srikrishna Podduturi answered on May 7, 2019 13:48 (last edited on May 7, 2019 13:54)

Thank you :)

I am trying to import file using MediaLibrary API in a seperate class library project. I am having issue while getting media library info - MediaLibraryInfo libraryInfo = MediaLibraryInfoProvider.GetMediaLibraryInfo("LibraryName", "SiteName");

But this is working fine in my website. I have referenced required Kentico libraries also. Could you please suggest.

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on May 7, 2019 15:43

Have you registered your library with AssemblyDiscoverable attribute? Please refer to docs for that.

0 votesVote for this answer Mark as a Correct answer

Srikrishna Podduturi answered on May 8, 2019 12:08

Thanks again for answering my questions with patience :)

I have a big list of products and i am thinking to save all product related images in a media library but for the product details page i will be needing only images related to that product. So is it possible to add a column in Media_File table to add ProductId or is it done in any other way? Please suggest.

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on May 8, 2019 15:08

Media file can be customizable and can have some extra fields:

Image Text

Or you can store relation between products and media files in a separate table (if one media file can be applied to different products).

0 votesVote for this answer Mark as a Correct answer

Srikrishna Podduturi answered on May 27, 2019 08:54

Hi Dmitry Bastron,

Could you please advise if we can add foreign key relationships between two tables created using page types. I want to get data from multiple tables which are related to each other and i want to get this data at once using relationships as we do in Entity Framework.

Thanks, Krishna.

0 votesVote for this answer Mark as a Correct answer

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