Search in sources :

Example 1 with BlobHttpHeaders

use of com.azure.storage.blob.models.BlobHttpHeaders 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 BlobHttpHeaders

use of com.azure.storage.blob.models.BlobHttpHeaders 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)

Example 3 with BlobHttpHeaders

use of com.azure.storage.blob.models.BlobHttpHeaders in project conductor by Netflix.

the class AzureBlobPayloadStorage method upload.

/**
 * Uploads the payload to the given azure blob name.
 * It is expected that the caller retrieves the blob name
 * using {@link #getLocation(Operation, PayloadType, String)} before making this call.
 *
 * @param path        the name of the blob to be uploaded
 * @param payload     an {@link InputStream} containing the json payload which is to be uploaded
 * @param payloadSize the size of the json payload in bytes
 */
@Override
public void upload(String path, InputStream payload, long payloadSize) {
    try {
        BlockBlobClient blockBlobClient = blobContainerClient.getBlobClient(path).getBlockBlobClient();
        BlobHttpHeaders blobHttpHeaders = new BlobHttpHeaders().setContentType(CONTENT_TYPE);
        blockBlobClient.uploadWithResponse(payload, payloadSize, blobHttpHeaders, null, null, null, null, null, Context.NONE);
    } catch (BlobStorageException | UncheckedIOException | UnexpectedLengthException e) {
        String msg = "Error communicating with Azure";
        logger.error(msg, e);
        throw new ApplicationException(ApplicationException.Code.BACKEND_ERROR, msg, e);
    }
}
Also used : BlobHttpHeaders(com.azure.storage.blob.models.BlobHttpHeaders) BlockBlobClient(com.azure.storage.blob.specialized.BlockBlobClient) UnexpectedLengthException(com.azure.core.exception.UnexpectedLengthException) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) UncheckedIOException(java.io.UncheckedIOException) BlobStorageException(com.azure.storage.blob.models.BlobStorageException)

Example 4 with BlobHttpHeaders

use of com.azure.storage.blob.models.BlobHttpHeaders in project ApplicationInsights-Java by microsoft.

the class ServiceProfilerUploader method createBlockBlobOptions.

BlobUploadFromFileOptions createBlockBlobOptions(File file, UploadContext uploadContext) {
    HashMap<String, String> metadata = new HashMap<>();
    metadata.put(BlobMetadataConstants.DATA_CUBE_META_NAME, uploadContext.getDataCube().toString().toLowerCase());
    metadata.put(BlobMetadataConstants.MACHINE_NAME_META_NAME, uploadContext.getMachineName());
    metadata.put(BlobMetadataConstants.START_TIME_META_NAME, TimestampContract.timestampToString(uploadContext.getSessionId()));
    metadata.put(BlobMetadataConstants.PROGRAMMING_LANGUAGE_META_NAME, "Java");
    metadata.put(BlobMetadataConstants.OS_PLATFORM_META_NAME, OsPlatformProvider.getOsPlatformDescription());
    metadata.put(BlobMetadataConstants.TRACE_FILE_FORMAT_META_NAME, "jfr");
    if (roleName != null && !roleName.isEmpty()) {
        metadata.put(BlobMetadataConstants.ROLE_NAME_META_NAME, roleName);
    }
    String fullFilePath = file.getAbsoluteFile().toString();
    return new BlobUploadFromFileOptions(fullFilePath).setHeaders(new BlobHttpHeaders().setContentEncoding("gzip")).setMetadata(metadata).setParallelTransferOptions(new ParallelTransferOptions().setBlockSizeLong(UPLOAD_BLOCK_LENGTH));
}
Also used : BlobHttpHeaders(com.azure.storage.blob.models.BlobHttpHeaders) HashMap(java.util.HashMap) BlobUploadFromFileOptions(com.azure.storage.blob.options.BlobUploadFromFileOptions) ParallelTransferOptions(com.azure.storage.blob.models.ParallelTransferOptions)

Aggregations

BlobHttpHeaders (com.azure.storage.blob.models.BlobHttpHeaders)4 BlobClient (com.azure.storage.blob.BlobClient)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 UnexpectedLengthException (com.azure.core.exception.UnexpectedLengthException)1 BlobStorageException (com.azure.storage.blob.models.BlobStorageException)1 ParallelTransferOptions (com.azure.storage.blob.models.ParallelTransferOptions)1 BlobUploadFromFileOptions (com.azure.storage.blob.options.BlobUploadFromFileOptions)1 BlockBlobClient (com.azure.storage.blob.specialized.BlockBlobClient)1 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)1 UncheckedIOException (java.io.UncheckedIOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ObjectId (org.bson.types.ObjectId)1