How to attach file public by default in comments section

I want to make attachment public by default when I copy & paste screenshot in comments section. So how to do ?
I have tried changing “Make Attachments Public by Default” in comment, file & main doctype but still it is not working.

You need to add custom logic in the server script for a specific doctype.

Example:

Here, I added logic for the Item Doctype. When a user adds an image in the comments, it will be saved as public.

Script Type:

  • DocType Event
    • Script Type: doc_type_event
    • Reference Document Type: File
    • Event: Before Save

Script:

if doc.attached_to_doctype == "Item" and doc.is_private:
    doc.is_private = 0

This script checks if the file is attached to the “Item” doctype and if it’s marked as private. If so, it changes it to public. We tested, so it’s worked properly.

@NCP I tried this but somehow it is not working…

I tested it, it working fine.

Please check it.

@NCP I am using frappe version 14.
When I just copy & paste any image in comment then it is becoming private image when comment is saved.