Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Power Apps Pro Dev & ISV
Suggested answer

Storing file in sql server table

Like (1) ShareShare
ReportReport
Posted on 20 Apr 2025 13:03:52 by 926
Hello everyone,
 
I have a canvas application in which the user uploads files using the attachment control.
 
How can I store the file in binary format in a table in SQL Server without using Power Automate or the API?
  • gikido Profile Picture
    926 on 21 Apr 2025 at 08:11:01
    Storing file in sql server table

    Thank you for your reply. In my case, I also want to store other file types (PDF, etc.).
     
    For the connector, I only use the SQL Server connector. (For the storage solution, the client doesn't want to use Azure Blob; they want all the data stored locally)
     
  • Suggested answer
    Michael E. Gernaey Profile Picture
    41,107 Super User 2025 Season 1 on 20 Apr 2025 at 21:53:14
    Storing file in sql server table
     
    Happy to help. 
     
    As for @ronaldwalcott they are looking for you to explain how as they do not know, so whatever approach you be teach them is what they need.
     
     
    and
     
    Example

    Certainly! Saving an image to SQL Server directly from a Power Apps Canvas app without using Power Automate involves a few steps. Here's a concise guide to help you achieve this:

    Step 1: Prepare Your SQL Server

     

    1. Create a Table: Ensure you have a table in your SQL Server database to store the image. The table should have a column of type VARBINARY(MAX) to store the image data.
      CREATE TABLE Images (
          Id INT PRIMARY KEY IDENTITY(1,1),
          ImageData VARBINARY(MAX)
      );
      


    2.  
     

    Step 2: Set Up Power Apps

     

    1. Create a Canvas App: Open Power Apps and create a new Canvas app.

    2. Add SQL Server Connection: Go to the Data tab, click on "Add data," and select SQL Server. Connect to your database.


    3.  
     

    Step 3: Add Controls to Your App

     

    1. Add an Image Control: Insert an Image control to capture or display the image.

    2. Add a Camera Control: Insert a Camera control to take pictures.

    3. Add a Button: Insert a Button control to trigger the save action.


    4.  
     

    Step 4: Write the Code

     

    1.  

      Capture the Image: Use the Camera control to capture the image and store it in a variable.

       
      Set(capturedImage, Camera1.Photo)
      

    2.  

      Convert Image to Binary: Power Apps does not directly support binary conversion, so you need to use a workaround by converting the image to a data URI and then to binary.

       
      Set(imageDataUri, JSON(capturedImage, JSONFormat.IncludeBinaryData))
      

    3.  

      Save Image to SQL Server: Use the Patch function to save the image data to SQL Server.

       
      Patch(
          '[dbo].[Images]',
          Defaults('[dbo].[Images]'),
          {
              ImageData: Mid(imageDataUri, Find(",", imageDataUri) + 1)
          }
      )
      


    4.  
     

    Step 5: Test Your App

     

    1. Run the App: Test the app by capturing an image and clicking the save button.

    2. Verify Data: Check your SQL Server table to ensure the image data is saved correctly.


    3.  
     

    Notes

     

    • Performance: Be mindful of the image size as large images can impact performance.

    • Security: Ensure your SQL Server connection is secure and follow best practices for handling binary data.


    •  
     

    By following these steps, you can save images directly to SQL Server from a Power Apps Canvas app without needing Power Automate. If you encounter any issues or need further customization, feel free to ask!


    I hope this helps and if so, please Mark as such and maybe a like
  • ronaldwalcott Profile Picture
    3,530 on 20 Apr 2025 at 18:22:37
    Storing file in sql server table
    Which connector are you using in the canvas app?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,660 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,004 Most Valuable Professional

Leaderboard
Loading started