def sign_upload(client: "Client", image_id: int, key: str, file_path: Path, team: str): """Obtains the signed URL from the back so that we can update to the AWS without credentials Parameters ---------- client: Client Client authenticated to the team where the put request will be made image_id: int Id of the image to upload key: str Path in the s3 bucket file_path: Path Path to the file to upload on the file system Returns ------- dict Dictionary which contains the server response """ file_format = file_path.suffix if is_image_extension_allowed(file_format): return client.post( endpoint=f"/dataset_images/{image_id}/sign_upload?key={key}", payload={ "filePath": str(file_path), "contentType": f"image/{file_format}" }, team=team, ) elif is_video_extension_allowed(file_format): return client.post( endpoint=f"/dataset_videos/{image_id}/sign_upload?key={key}", payload={ "filePath": str(file_path), "contentType": f"video/{file_format}" }, team=team, )
def _split_on_file_type(files: List[Path]): """Splits a single list of files into images and videos based on their extension Parameters ---------- files : list[Path] List of files to split according to their type Returns ------- images, videos : list[Path] List of image and videos, respectively """ images = [] videos = [] for file_path in files: suffix = file_path.suffix if is_image_extension_allowed(suffix): images.append(file_path) elif is_video_extension_allowed(suffix): videos.append(file_path) else: raise UnsupportedFileType(file_path) return images, videos
def it_returns_false_for_unknown_extensions(): assert not is_video_extension_allowed(".not_video")
def it_returns_true_for_allowed_extensions(): assert is_video_extension_allowed(".mp4")