Skip to main content Skip to complementary content
  • New archived content: Talend MDM, Talend Data Catalog 8.0, and Talend 7.3 products reached their end of life in 2024. Their documentation was moved to the Talend Archive page and will no longer receive content updates.
Close announcements banner

Creating a Job to insert BLOB data into a MySQL table

Create a Job to iterate over the picture files in the "C:/Talend/images" folder and insert each one into the blobdemo table.

Screenshot of the Job in the Designer.
  • The tFileList iterates all pictures in the "C:/Talend/images" folder.
  • The tFixedFlowInput gets the current file path and outputs it.
  • The tMap calls the routine to read the files as byte array.
  • The tMysqlOutput inserts the BLOB data into the target table.

Set up the Job

Procedure

  1. Create a standard Job and enter its name, in this example Insertblobdatatodatabase.
  2. Place the following components to the design workspace: tFileList, tFixedFlowInput, tMap and tMysqlOutput.
  3. Connect the tFileList and the tFixedFlowInput using an Iterate link.
  4. Connect the tFixedFlowInput to the tMap and the tMap to the tMysqlOutput using Row > Main links.

Configure the data input

Procedure

  1. In the Basic settings view of the tFileList, in the Directory field, click the [...] button to browse to the directory, in this example "C:/Talend/images".
    Screenshot of the component basic settings.
  2. In the FileList Type list, select Files.
  3. Click the [+] button to add a row in the Files area and define a filter to match files. In this example, type in "*.png" to retrieve all picture files.
  4. In the Basic settings view of the tFixedFlowInput, click the Edit Schema button and add a column, filepath of type String.
    Screenshot of the component schema.

    The defined column displays in the Values panel.

  5. Click in the Value cell of the filepath column and press Ctrl+Space to access the global variable list.
  6. From the global variable list, select tFileList_1_CURRENT_FILEPATH.
    Screenshot of the component basic settings.

Configure the tMap component to call the user routine

Before you begin

  • You have created a user routine.

Procedure

  1. Double-click the tMap to open the map editor.
  2. Click the [+] button to add an output table named out1.
  3. At the bottom right corner (out1) of the Schema editor view, click the [+] button to add a row, picture of type byte.
    Screenshot of the Schema editor view.
  4. In the Expression field of the picture column on the output side, type in MyRoutineDemo.ByteArrayFromFile(row1.filepath).
  5. Click OK to validate these changes and accept the propagation prompted by the dialog box that pops up.

Insert the BLOB data into the target table

Before you begin

  • You have created a MySQL table.

Procedure

  1. In the design workspace, double-click the tMysqlOutput component to display its Basic settings view and set its parameters.
  2. Set Property Type to Repository and then click the three-dot button to select the correct DB connection.
    Screenshot of the component basic settings.

    The connection details display automatically in the corresponding fields.

  3. Click the [...] button next to the Table field and select the target table, blobdemo in this example.

Executing the Job to insert BLOB data into a MySQL table

Procedure

  1. Press Ctrl+S to save your Job.
  2. Press F6 to execute the Job.
  3. Query the blobdemo table to verify that the pictures were inserted successfully.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!