use of com.saransh.vidflow.exceptions.UnsupportedFormatException in project vidflow-backend by CryptoSingh1337.
the class VideoOperationsServiceImpl method uploadVideo.
@Override
public List<String> uploadVideo(String username, MultipartFile videoFile) {
if (validateVideoFileType(videoFile.getContentType())) {
log.debug("Uploading video...");
List<String> videoDetails = new ArrayList<>(2);
String id = new ObjectId().toString();
videoDetails.add(id);
BlobClient blobClient = blobContainerClient.getBlobClient(generateUploadBlobName(username, id, getFileType(Objects.requireNonNull(videoFile.getOriginalFilename()))));
try {
BlobParallelUploadOptions blobParallelUploadOptions = new BlobParallelUploadOptions(videoFile.getInputStream());
blobParallelUploadOptions.setHeaders(new BlobHttpHeaders().setContentType(videoFile.getContentType()));
blobClient.uploadWithResponse(blobParallelUploadOptions, null, Context.NONE);
videoDetails.add(blobClient.getBlockBlobClient().getBlobUrl());
return videoDetails;
} catch (IOException ignored) {
throw new UploadFailedException("Video is unable to upload");
}
} else {
throw new UnsupportedFormatException("Unsupported video format");
}
}
use of com.saransh.vidflow.exceptions.UnsupportedFormatException in project vidflow-backend by CryptoSingh1337.
the class ThumbnailOperationsServiceImpl method uploadThumbnail.
@Override
public String uploadThumbnail(String username, String videoId, MultipartFile thumbnail) {
if (validateImageFileType(thumbnail.getContentType())) {
log.debug("Uploading thumbnail...");
BlobClient blobClient = containerClient.getBlobClient(generateBlobName(username, videoId, getFileType(Objects.requireNonNull(thumbnail.getOriginalFilename()))));
try {
BlobParallelUploadOptions blobParallelUploadOptions = new BlobParallelUploadOptions(thumbnail.getInputStream());
blobParallelUploadOptions.setHeaders(new BlobHttpHeaders().setContentType(thumbnail.getContentType()));
blobClient.uploadWithResponse(blobParallelUploadOptions, null, Context.NONE);
return blobClient.getBlockBlobClient().getBlobUrl();
} catch (IOException e) {
throw new UploadFailedException("Thumbnail is unable to upload");
}
} else {
throw new UnsupportedFormatException("Unsupported thumbnail format");
}
}
Aggregations