malthe commented on code in PR #6443:
URL: https://github.com/apache/nifi/pull/6443#discussion_r996273173


##########
nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/main/java/org/apache/nifi/processors/azure/storage/PutAzureBlobStorage_v12.java:
##########
@@ -121,18 +146,47 @@ public void onTrigger(final ProcessContext context, final 
ProcessSession session
             if (createContainer && !containerClient.exists()) {
                 containerClient.create();
             }
-            BlobClient blobClient = containerClient.getBlobClient(blobName);
 
+            BlobClient blobClient = containerClient.getBlobClient(blobName);
+            final BlobRequestConditions blobRequestConditions = new 
BlobRequestConditions();
+            Map<String, String> attributes = new HashMap<>();
+            attributes.put(ATTR_NAME_CONTAINER, containerName);
+            attributes.put(ATTR_NAME_BLOBNAME, blobName);
+            attributes.put(ATTR_NAME_PRIMARY_URI, blobClient.getBlobUrl());
+            attributes.put(ATTR_NAME_LANG, null);
+            attributes.put(ATTR_NAME_MIME_TYPE, "application/octet-stream");
             long length = flowFile.getSize();
 
-            try (InputStream rawIn = session.read(flowFile);
-                 BufferedInputStream bufferedIn = new 
BufferedInputStream(rawIn)) {
-                blobClient.upload(bufferedIn, length);
+            try {
+                if (conflictResolution != 
AzureStorageConflictResolutionStrategy.REPLACE_RESOLUTION) {
+                    blobRequestConditions.setIfNoneMatch("*");
+                }
+
+                try (InputStream rawIn = session.read(flowFile)) {
+                    final BlobParallelUploadOptions blobParallelUploadOptions 
= new BlobParallelUploadOptions(toFluxByteBuffer(rawIn));
+                    
blobParallelUploadOptions.setRequestConditions(blobRequestConditions);
+                    Response<BlockBlobItem> response = 
blobClient.uploadWithResponse(blobParallelUploadOptions, null, Context.NONE);
+                    BlockBlobItem blob = response.getValue();
+                    attributes.put(ATTR_NAME_BLOBTYPE, 
BlobType.BLOCK_BLOB.toString());
+                    attributes.put(ATTR_NAME_ETAG, blob.getETag());
+                    attributes.put(ATTR_NAME_LENGTH, String.valueOf(length));
+                    attributes.put(ATTR_NAME_TIMESTAMP, 
String.valueOf(blob.getLastModified()));
+                }
+            } catch (BlobStorageException e) {
+                if (conflictResolution == 
AzureStorageConflictResolutionStrategy.FAIL_RESOLUTION) {
+                    throw e;
+                }
+                final BlobErrorCode errorCode = e.getErrorCode();
+                if (errorCode == BlobErrorCode.BLOB_ALREADY_EXISTS) {

Review Comment:
   In 0d394ed99f93f2694df444ad86db13621fcb9c7f this has now become clearer for 
the reader:
   ```java
   if (alreadyExists && ignore) {
       getLogger().info("Blob already exists: remote blob not modified. 
Transferring {} to success", flowFile);
   } else {
       throw e;
   }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to