Search in sources :

Example 1 with UnsupportedFormatException

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");
    }
}
Also used : BlobParallelUploadOptions(com.azure.storage.blob.options.BlobParallelUploadOptions) BlobHttpHeaders(com.azure.storage.blob.models.BlobHttpHeaders) BlobClient(com.azure.storage.blob.BlobClient) UnsupportedFormatException(com.saransh.vidflow.exceptions.UnsupportedFormatException) UploadFailedException(com.saransh.vidflow.exceptions.UploadFailedException) ObjectId(org.bson.types.ObjectId) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 2 with UnsupportedFormatException

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");
    }
}
Also used : BlobParallelUploadOptions(com.azure.storage.blob.options.BlobParallelUploadOptions) BlobHttpHeaders(com.azure.storage.blob.models.BlobHttpHeaders) BlobClient(com.azure.storage.blob.BlobClient) UnsupportedFormatException(com.saransh.vidflow.exceptions.UnsupportedFormatException) UploadFailedException(com.saransh.vidflow.exceptions.UploadFailedException) IOException(java.io.IOException)

Aggregations

BlobClient (com.azure.storage.blob.BlobClient)2 BlobHttpHeaders (com.azure.storage.blob.models.BlobHttpHeaders)2 BlobParallelUploadOptions (com.azure.storage.blob.options.BlobParallelUploadOptions)2 UnsupportedFormatException (com.saransh.vidflow.exceptions.UnsupportedFormatException)2 UploadFailedException (com.saransh.vidflow.exceptions.UploadFailedException)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)1 ObjectId (org.bson.types.ObjectId)1