Custom directory path for files uploaded via "attach" field type

In a custom doctype, I have “attach” field types to upload specific documents. I want those documents to be stored in a specific place in the file manager. Is there a way to edit the “attach” field type to have it that way. Thank You.

1 Like

Does anyone have an update on this?

I have the Same Problem. Please help us. I am proving the below link.

Thank you.

1 Like

Is there any solution ?

Thanks and Regards

No I have the same question ?
If someone from the frappe team could answer

This could work…

  • add an on_update hook for File (in
  • check if it is attached to your custom doctype, if so move it to your required folder

@vijaywm Thanks, man! Did you find any alternative ways?

No, not tried.

I have used the below code to solve the problem:

def capture(file=None):
    result , response_api = image_api(file)
    if result:

        docname = frappe.get_request_header("Referer").split("/")[-1]
        file_content = frappe.local.uploaded_file
        file_name_old = frappe.local.uploaded_filename

        folder_path = f"/home/frappe_dev/frappe-bench/sites/developement.expd/public/files"
        os.makedirs(folder_path, exist_ok=True)

        file_path = os.path.join(folder_path, file_name_old)

        with open(file_path, "wb") as file:
        host =

        # Check if the port is needed (adjust according to your environment)
        port = ":8000" if "localhost" in host or "" in host else ""

        # Construct the dynamic URL
        sys_file_path = f"http://{host}{port}/files/{file_name_old}"
        email_id ='user')

        file_doc = frappe.new_doc("File") = "random"
        file_doc.file_name = file_name_old
        file_doc.file_url = sys_file_path
        file_doc.attached_to_name = docname
        file_doc.folder = "Home"
        file_doc.attached_to_doctype = "Face Detection passport"
        file_doc.attached_to_field = 'upload_image'


        frappe.db.set_value("File",, "file_url", f"{sys_file_path}")


    return str(response_api.json())
frappe.ui.form.on("Face Detection passport", {
	upload_image: function (frm) {
        if (frm.doc.__islocal) {
   => {
        } else {

function uploadFile(frm) {
    new frappe.ui.FileUploader({
        method: 'frappe.image_detection.doctype.face_detection_passport.face_detection_passport.capture',
        make_attachments_public: "False",
        dialog_title: "Upload Files",
        disable_file_browser: "False",
        allow_link: "True",
        frm: frm,
        on_success(file, response) {
            frappe.msgprint(`${"Server response:"+response.message}`, "Message");  // Log the response for debugging

                message: __('File uploaded.'),
                indicator: 'green'
            }, 5);

1 Like

im finding a solution to disable all option except my device , and upload, from upload dialoged ,

if any way is there it will be help full for me , because we need to restrict user to find out other user document, from library ,