Image save issue in Doctype

The image is not uploading properly when I try to save it in doctype. For your reference, please see the below image and code.


file_doc = save_file(f’{file_name1}.{form_image.split(“.”)[-1]}‘, form_image, ‘UserData’, ‘register.html’, is_private=0, df=‘profile_picture’)
img_url = file_doc.file_url.split(file_name1.replace(“\”,“”).replace(“//”,’'))[0] + form_image.replace(“//”,“”)
main_doc.image = img_url



Hi @Priyank_Suthar,

I haven’t too much idea but add try Exception scenario and check it.

    file_doc = save_file(f'{file_name1}.{form_image.split(".")[-1]}', form_image, 'UserData', 'register.html', is_private=0, df='profile_picture')

    img_url = file_doc.file_url

    main_doc.image = img_url

    print("Image uploaded and document updated successfully.")
except Exception as e:
    print(f"Error: {e}")

This code encapsulates the image uploading process in a try-except block to catch any errors that might occur during file saving or document updating. If an error occurs, it will print an error message. Otherwise, it will print a success message.

Make sure to replace main_doc with the actual variable representing your document, and ensure that the file paths and document fields are correctly specified.

I hope this helps.

Thank You!

1 Like