web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Storing file in sql se...
Power Apps
Suggested Answer

Storing file in sql server table

(1) ShareShare
ReportReport
Posted on by 992
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?
I have the same question (0)
  • ronaldwalcott Profile Picture
    3,847 Super User 2025 Season 2 on at
    Which connector are you using in the canvas app?
  • Suggested answer
    Michael E. Gernaey Profile Picture
    53,362 Super User 2025 Season 2 on at
     
    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
  • gikido Profile Picture
    992 on at

    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)
     

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 711 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 319 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard