File size: 1,278 Bytes
a7b5515
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
import os.path
import cloudinary
import cloudinary.uploader
import cloudinary.api

# Import the CloudinaryImage and CloudinaryVideo methods for the simplified syntax used in this guide
from cloudinary import CloudinaryImage
from cloudinary import CloudinaryVideo

from facefusion.filesystem import is_image, is_video

cloudinary.config( 
    cloud_name = os.environ.get('CLOUDINARY_CLOUD_NAME'), 
    api_key = os.environ.get('CLOUDINARY_API_KEY'), 
    api_secret = os.environ.get('CLOUDINARY_API_SECRET'),
    secure = True
)

def is_large_file(file_path : str) -> bool:
    return os.path.getsize(file_path) > 100*1*1024*1024

def upload_file(file_path : str):
    file_resource_type = ''
    if is_image(file_path):
        file_resource_type = 'image'
    if is_video(file_path):
        file_resource_type = 'video'
    if is_large_file(file_path):
        return cloudinary.uploader.upload_large(file_path, 
            folder = os.environ.get('CLOUDINARY_UPLOAD_FOLDER'), 
            overwrite = True, 
            resource_type = file_resource_type)
    else:
        return cloudinary.uploader.upload(file_path, 
            folder = os.environ.get('CLOUDINARY_UPLOAD_FOLDER'), 
            overwrite = True, 
            resource_type = file_resource_type)