use of com.azure.storage.blob.options.BlobParallelUploadOptions 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.azure.storage.blob.options.BlobParallelUploadOptions in project OpenSearch by opensearch-project.
the class AzureBlobStore method writeBlob.
public void writeBlob(String blobName, InputStream inputStream, long blobSize, boolean failIfAlreadyExists) throws URISyntaxException, BlobStorageException, IOException {
assert inputStream.markSupported() : "Should not be used with non-mark supporting streams as their retry handling in the SDK is broken";
logger.trace(() -> new ParameterizedMessage("writeBlob({}, stream, {})", blobName, blobSize));
final Tuple<BlobServiceClient, Supplier<Context>> client = client();
final BlobContainerClient blobContainer = client.v1().getBlobContainerClient(container);
final BlobClient blob = blobContainer.getBlobClient(blobName);
try {
final BlobRequestConditions blobRequestConditions = new BlobRequestConditions();
if (failIfAlreadyExists) {
blobRequestConditions.setIfNoneMatch(Constants.HeaderConstants.ETAG_WILDCARD);
}
SocketAccess.doPrivilegedVoidException(() -> {
final Response<?> response = blob.uploadWithResponse(new BlobParallelUploadOptions(inputStream, blobSize).setRequestConditions(blobRequestConditions).setParallelTransferOptions(service.getBlobRequestOptionsForWriteBlob()), timeout(), client.v2().get());
logger.trace(() -> new ParameterizedMessage("upload({}, stream, {}) - status [{}]", blobName, blobSize, response.getStatusCode()));
});
} catch (final BlobStorageException se) {
if (failIfAlreadyExists && se.getStatusCode() == HttpURLConnection.HTTP_CONFLICT && BlobErrorCode.BLOB_ALREADY_EXISTS.equals(se.getErrorCode())) {
throw new FileAlreadyExistsException(blobName, null, se.getMessage());
}
throw se;
} catch (final RuntimeException ex) {
// are swallowed and wrapped into runtime one (see please Exceptions.ReactiveException).
if (ex.getCause() != null) {
Throwables.rethrow(ex.getCause());
} else {
throw ex;
}
}
logger.trace(() -> new ParameterizedMessage("writeBlob({}, stream, {}) - done", blobName, blobSize));
}
use of com.azure.storage.blob.options.BlobParallelUploadOptions 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