File size: 553 Bytes
a3386d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import cloudinary
from cloudinary.uploader import upload
import io
from fastapi import UploadFile


# Define the upload_file function as an async function
async def upload_file(file: UploadFile, new_img_file_name: str, dir_address: str):
    try:

        # Upload the file to Cloudinary
        result = upload(
            file=file.file,
            resource_type="auto",
            public_id=new_img_file_name,
            folder=dir_address,
        )

        return result
    except Exception as error:
        print(error)
        raise error