Home > Enterprise >  Unable to upload file to azure blob container on new file creation using apache camel
Unable to upload file to azure blob container on new file creation using apache camel

Time:12-31

I want to upload files created in hello directory to azure blob container. I was able to upload the exact file name within route URL. But, when i place a placeholder to read the filename it was not working.

Working:

.to("azure-storage-blob://accName/container?blobName=text.txt&operation=uploadBlockBlob&serviceClient=#serviceClient")

Not Working:

.to("azure-storage-blob://accName/container?blobName=${header.CamelFileName}&operation=uploadBlockBlob&serviceClient=#serviceClient")

Here is the code:

  @Service
    public class SftpWatcherRoute extends RouteBuilder {
    
    
      @Override
      public void configure() {
    
    
        from("file-watch:hello?events=CREATE&antInclude=**/*.txt&recursive=true")
            .routeId("fileWatch")
            .log("File Name: ${header.CamelFileName}")
            .to("direct:uploadFileToBlob")
            .end();
    
        from("direct:uploadFileToBlob")
            .routeId("uploadFile")
            .log("Azure Blob Triggered: ${header.CamelFileName}")
            .to("azure-storage-blob://accName/container?blobName=${header.CamelFileName}&operation=uploadBlockBlob&serviceClient=#serviceClient")
            .log("Blob Upload Successful")
            .log("${body}")
            .end();
    
      }
    }

I want to read the files created and upload it to azure blob container can someone help me on this ?

CodePudding user response:

Try with using the simple expression and recipient list pattern

with this it is easy to dynamically construct a URI based on a message header value

Examples:

.to("freemarker://templateHome/${body.templateName}.ftl")//It is in valid 

To fix the above problem we can use either toD or recipientList.

Using toD

.toD("freemarker://templateHome/${body.templateName}.ftl")

Using the recipientList

.recipientList(simple("freemarker://templateHome/${body.templateName}.ftl"))

For more details refer this document

  • Related