How to copy image from sqlserver in varbinary to Azure Blob storage using azure data factory

manish verma 516 Reputation points
2026-08-13T10:11:50.02+00:00

Hi all,

“We are looking for a sample Copy Activity in Azure Data Factory to copy image data from Oracle/SQL databases into Azure Blob Storage as image files. The challenge we face is that when copying from relational databases, we are unable to perform a true binary copy. Even when using queries and casting the image field to VARBINARY, the output does not preserve

Azure Data Factory
Azure Data Factory

An Azure service for ingesting, preparing, and transforming data at scale.


1 answer

Sort by: Most helpful
  1. Marcin Policht 105.8K Reputation points MVP Volunteer Moderator
    2026-08-13T11:04:26.9266667+00:00

    For the pipeline, use a Lookup Activity first to retrieve the identifiers and file names rather than retrieving the potentially large binary payload. For example, the Lookup can execute SELECT Id, FileName FROM ImagesTable. The Lookup output then becomes the input to a ForEach Activity using @activity('LookupActivityName').output.value. Set Sequential to False if the database and ADF integration runtime can support parallel processing.

    Inside the ForEach, use a Copy Activity with a parameterized source query such as

    SELECT ImageColumn FROM ImagesTable WHERE Id = @{item().Id}
    

    The source should return the actual binary/BLOB column, not a Base64 or hexadecimal representation. Configure the Azure Blob Storage sink as Binary format and use the current item's file name, such as @item().FileName, for the destination file name. This results in one Blob per database row, with the Blob containing the original binary image bytes.

    For example, the overall flow is:

    Lookup → ForEach → Copy Activity

    The Lookup returns something like:

    SELECT Id, FileName FROM ImagesTable
    The Copy Activity inside the ForEach retrieves the actual image:
    SELECT ImageColumn FROM ImagesTable WHERE Id = @{item().Id}
    The Blob destination then uses a dynamic file name such as:
    @item().FileName
    

    Casting an image/BLOB column to VARBINARY does not by itself solve the problem. If ADF subsequently serializes the relational result into a tabular format, the resulting file is not the original image binary. The Copy Activity should preserve the source column as binary and the Blob sink must write it as Binary. For cases where the ADF Copy Activity cannot correctly materialize the database BLOB as the required individual binary file, an Azure Function is a suitable alternative - the Function can retrieve the BLOB directly from Oracle or SQL Server and write the exact byte stream to Blob Storage.

    For very large numbers of images, I would also consider avoiding one Lookup/ForEach iteration per image because it creates a database query and Copy Activity execution for every row. In that situation, batching or an Azure Function-based approach can be more efficient.


    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.