Kentico 8 generate missing attachment files using AttachmentBinary value by api

Lucsa Han asked on June 28, 2019 05:50

I have a kentico 8 website and some of its pages have images as attachments. for some reasons, some of the attachments files are missing(attachments are stored in file system at the moment). What happened is if I got to website to visit that from page as anonymous user, all images links are broken and return 404, if I logged in as global admin, I can see the image the front end page, and if I just republish the page(dont need to make any changes), then the images in the page are good, and I can see all attachment files are generated in the proper folder(there are no corresponding attachment files before re publish).

from the data base, I can see the [AttachmentBinary] field in [CMS_AttachmentHistory] (in [CMS_Attachment] is empty though) does have data for those "missed file" attachments, my guess is kentico use that binary data to regenerate the files when the page is republished.

As I got quite a lot of these pages I want to do the batch update through API


Correct Answer

Brenden Kehren answered on June 28, 2019 06:16

Double check your settings are as you want them, either store in database or file system or both. Next go to the System app and go to attachments. There you can see which files are stored in the file system or the database or both. It will even let you change where the file is stored.

I'd suggest those things first before writing code.

0 votesVote for this answer Unmark Correct answer

Recent Answers

Lucsa Han answered on June 28, 2019 06:46

@Brenden, the files in my site are stored in both file system and database, from attachments in System app, I can see the ones I missing are saying "No" for both "Stored in DB" and "Stored in FS".

The thing is I got about 70k files in total there and I guess I can check how it determine the files are not in file system in the source code of that page then I can narrow the list down to the one I want then follow the way how it "Copy to file system" to copy all files?

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on June 28, 2019 15:14

If you wanted to write some code you can simply check the Attachment's binary file to see if it's stored in the db. If you want to check if it's in the file system, there's a method for that as well based on the attachment GUID. So not a difficult set of code to write. If you have 70k files, it may be more time consuming to use the already built in tools vs. writing code.

0 votesVote for this answer Mark as a Correct answer

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