Make attachments public by default (for Web Forms)?

How to set attachments to public in a webform? I already have it set for the doctype itself, but how to force attachments to public folder “/files/” instead of private folder “/private/files/”

Any help?

Hello @Yamen_Zakhour Did you found any solution for this ?

I actually customized the file doctype to create a duplicate file that is set to public and then deleted the private one
(Only triggers on files that are linked to the specific docfield)

@Yamen_Zakhour Can you provide the code ?

if doc.attach_file:
    try:
        file_docs = frappe.get_all('File', filters={'file_url': doc.attach_file}, fields=['name', 'is_private', 'file_url'])
        if file_docs:
            file_doc = frappe.get_doc('File', file_docs[0]['name'])
            if file_doc.is_private:
                new_file_doc = frappe.copy_doc(file_doc)
                new_file_doc.is_private = 0
                new_file_doc.file_name = f"{doc.name}_{new_file_doc.content_hash}.{new_file_doc.file_type.lower()}"
                new_file_doc.save(ignore_permissions=True)
                doc.attach_file = new_file_doc.file_url
                doc.save(ignore_permissions=True)
                file_doc.delete(ignore_permissions=True)
        else:
            frappe.log_error("File not found.")
    except Exception as e:
        frappe.log_error(f"Error handling attachment for {doc}: {str(e)}", "Attachment Handling Exception")