Articles in this section
Category / Section

How to download image using hyperlinks in JSON file?

2 mins read

Introduction

This document explains the steps involved in downloading images using hyperlinks available in JSON file.

Objective

To create a workflow to parse JSON file and to download images using parsed hyperlink value.

List of processors used in workflow

Processors

Description

GetFile

Creates Flowfile from given file in the directory.

SplitJson

Splits JSON array element into multiple Flowfiles.

EvaluateJsonPath

Evaluates JSON and resultants value will be assigned to the given attribute.

InvokeHTTP

Gets response as Flowfile using given image URL.

UpdateAttribute

Gets filename with extension using expression language support.

PutFile

Stores Flowfile content into the given output directory.

 

Workflow overview

Workflow overview

Steps involved in workflow

Step 1

Drag and drop the GetFile processor into canvas area.

Drag and drop

Change the processor name with your convenient description.

Change the processor

In scheduling tab, select scheduling strategy and enter run schedule as your wish. Please refer to the following screenshot:

Scheduling strategy

In properties tab, enter value for the Input Directory, File Filter and Keep Source File properties as mentioned in following screenshot:

 

The sample JSON file format used in this sample is

{

 "response": [

{"image": "https://cdn.syncfusion.com/content/images/products/data-integration/DIP-banner.jpg"},

{"image":"https://cdn.syncfusion.com/content/images/company-logos/Syncfusion_Logo_Image.png"},

{"image":"http://www.syncfusion.com/content/images/nuget/sync_logo_icon.png"}

           ]

}

Step 2

Drag and drop the SplitJson processor into canvas area. Connect the GetFile processor with the SplitJson processor with “Success” relationship. In properties tab, enter value for the JsonPath Expression as “response” (Need to enter JSON array. Please refer to the previous JSON file format) mentioned in following screenshot:

Note: To ignore the failure case, select the auto-terminate option for corresponding relationships. Please refer to the following screenshot:

Step 3:

Drag and drop the EvaluateJsonPath processor into canvas area. Connect the SplitJson processor with the EvaluateJsonPath processor with “split” relationship. In properties tab, select required option for the Destination property. Also add the new attribute “imagePath” and enter the expression language to get image path from JSON response as shown in the following screenshot:

Step 4

Drag and drop the InvokeHTTP processor into canvas area. Connect the EvaluateJsonPath processor with the InvokeHTTP processor with “matched” relationship. In properties tab, enter value for the required properties as shown in the following screenshot:

Step 5

Drag and drop the UpdateAttribute processor into canvas area. Connect the InvokeHTTP processor with the UpdateAttribute processor with “Response” relationship.  In properties tab, enter the required filename using the expression language for the newly added attribute “filename” as shown in the following screenshot:

Step 6

Drag and drop the PutFile processor into canvas area. Connect the UpdateAttribute processor with the PutFile processor with “success” relationship. Double click the processor to configure it. In settings tab, auto-terminate “failure” and “success” relationships and in properties tab, enter value for the required properties as shown in the following screenshot:

Step 7:

After the previous configurations have been done, start the workflow. It will generate resultant Flowfile as image file in the given output directory.

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied