简体   繁体   中英

Django image attachment FileNotFoundError

I want to generate a thumbnail of an attachment uploaded by the user to my Django site, but for some reason I get the following error:

FileNotFoundError: [Errno 2] No such file or directory: '/media/tenant-2cadb939-306a-43f2-aa53-eb086a4f74b9/AssignedCampaign/2021-2/53676e7d-c95d-4348-a_581e4TM.png'

Although the file does exist.

This is the code I'm using:

if a.attachment:
       # get path of attachment without the attachment name
       cache_path = a.full_path.replace('/'+a.full_path.split('/')[-1], '') + '/preview_cache'
       
       log.info('>>>>>>>>>> %s', cache_path)
       
       preview_manager = PreviewManager(cache_path, create_folder=True)
       preview = preview_manager.get_jpeg_preview(a.full_path, width=100, height=200)

What I had to do is to give the absolute path of the file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM