If you are talking about the File type attachment then you should explore the code from Data-WorkAttach-File.pySaveContent Declare trigger rule. If you are talking about Screenshot or ScanDocument type attachments then you should look into SaveAttachment activity of Data-WorkAttach-Screenshot or Data-WorkAttach-ScanDocument classes respectively. Hope this might be helpful to you.
You are seeing pyattachment page because the attachment is already stored in the data base . When you attach any attachment pega builds the dragDropFileUpload page list and stores the attachment in base64 .It saves the attachment in pc_data_workattach when you click on submit/attach ,provided you have not changed the class mapping.
If you are using the OOTB flow action pyAttachContent to attach an attachment then by default it invokes the post processing activity pzSaveAttachments , this activity will do the necessary saving , you don't have to do anything .