How to upload image programatically

i have generated an image of qrcode programatically now i want to save generated file when i save the doctype. can any one help me to find some other situation like this which are done in erpnext


Isn’t it possible to just for the code/text itself and let the browser display QR code (like a font) ?

@Not_a_countant i want to save it when i click save like we upload image to item but i want to save it pro-grammatically because i am generating it on before save method.

I have used below code to save file details to files table

    		site = get_site_path()
		# print os.rename("qrcode.png", site+"qrcode.png")
		img = qrcode.make(daa_box_number)"/public/files/{0}".format("qrcode.png"))
		qr_code = frappe.new_doc("File")
		qr_code.file_name = "qrocde.png"
		qr_code.attached_to_name =
		qr_code.attached_to_doctype = self.doctype
		qr_code.file_url    = get_site_path()+"/public/files/{0}".format("qrcode.png")

this worked for me thanks

1 Like