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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / upload dialogue with a...
Power Apps
Answered

upload dialogue with attachment control

(0) ShareShare
ReportReport
Posted on by 304

Hi everyone,

I'm currently building an upload dialogue inside my PowerApp. The goal is, that the user selects a file and uploads it to a SP library (done via a flow) and if the flow is completed, the app should notify the user. I got it to work with the image upload control.

But now I got the instruction, that the users not only need to upload images, but also other file types like pdf, videos etc. So I changed the image upload control to an attachment control like in formulas and swapped the name of the image control to the attachment control in my function. But it now throws an error saying "The column "file.contentBytes" in the data source expects type "blob" but you are providing type "table". I don't really get what type blob is or why it doesn't work with the attachments control, but does with the image control.  Also, I did stick to the video about uploading by Reza Dorrani (https://www.youtube.com/watch?v=QUwzvUXgj58) and even if I delete the function and re-add it exactly like he did, it is still the same.

 

I'll show you some screenshots:

 

LisKr_0-1712741429377.png

That's what it is like with the old image control. ⬆️

 

 

 

LisKr_1-1712741520912.png

An here it is using the attachment control. ⬆️

Even if I delete the if statement and the notify function, the error is still the same.

 

What am I doing wrong here? And what do I do, if I want more than one file to be uploaded? I saw a solution with a ForAll function, but I'm not sure how to connect that with notifying the user.

 

Categories:
  • Verified answer
    WarrenBelz Profile Picture
    156,940 Most Valuable Professional on at

    Hi @LisKr ,

    Can you please remember to post your code in Text as it saves re-typing here. This code is OCR'd, so please watch spelling. You need to refer to the attachment control Value - not Image

    If( 
     MLIProductionInstructions-MachineGrade:CreateFolder+uploadimage.Run( 
     InputDetaiLsMachineGradelD.Text;
     {
     file: 
     {
     contentBytes: First(DetailsMachineUploadAttachments.Attachments).Value; 
     name: First(DetailsMachineUploadAttachments.Attachments).Name
     }
     }
     ).status = "Completed"; 
     Notify("Upload successful !”;Success)
    );;

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • LisKr Profile Picture
    304 on at

    Thanks for your reply! I already tried refering to the attachment control (as you can see in my second screenshot), that's when the error started to appear. This was my code:

     

    If('MLIProductionInstructions-MachineGrade:CreateFolder+uploadimage'.Run(
     InputDetailsMachineID.Text;
     {
     file: {
     contentBytes: DetailsMachineUploadAttach.Attachments.Value;
     name: DetailsMachineUploadAttach.Attachments.Name
     }
     }
     ).status = "Completed"; Notify("Upload successful!";NotificationType.Success)
    );;
    Notify(
     "Upload successful!";
     NotificationType.Success
    )

     

     

     

    I just tried your code and it still throws the same error, unfortunately.

    Edit: I tried it again and it seems to work. I might have had a mistake in the name.

    The following questions still remain:

     

    Can you explain why I need to use First function? Or what do I need to do, if I want to upload more than just one file at the same time?

     

  • WarrenBelz Profile Picture
    156,940 Most Valuable Professional on at

    @LisKr ,

    The issue is that an Attachment Control content is a Table and you only want one record from that Table. It is probably better to use Last() so you can keep adding as you have mentioned.

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • LisKr Profile Picture
    304 on at

    I didn't know that it's a table. Good to know! I'm quite new to PowerApps and try to teach myself piece by piece whenever I need something new, so I apologize if my questions seem kinda odd or stupid.

     

    So why do we have to use either First() or Last()? Can't I use all the records of that table at once? And what about that solution with ForAll() I have seen, is it  a good practice? It was something like

     

     

    ForAll(
     AttachmentsControlName.Attachments As FILE,
     UploadFileToDocumentLibrary.Run(
     {
     contentBytes: FILE.Value,
     name: FILE.Name
     }
     )
    );

     

     

     

    I don't really get what that "as file" means. I've also seen someone use "as document" instead of "as file", so is document or file just kind of a random word to make it easier to refer to the files?

    And how could I nest that code into my if statment with the notification?

  • Verified answer
    WarrenBelz Profile Picture
    156,940 Most Valuable Professional on at

    @LisKr ,

    If you are using the Attachment control solely for this purpose and do not set the MaxAttachments to 1 (as I do), then Last() is probably better (from a user perspective), but that is superseded by your most recent question. Yes, you can call the As variable whatever you want and attach them all

    ForAll(
     AttachmentsControlName.Attachments As _Files,
     UploadFileToDocumentLibrary.Run(
     {
     contentBytes: _Files.Value,
     name: _Files.Name
     }
     )
    );

    Just be careful on (particularly) mobile devices that you do not try to add too many large files.

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

     

     

  • LisKr Profile Picture
    304 on at

    Thanks for your explanation. That really helps!

     

    Is there a maximum of files to upload at once that you recommend so it doesn't affect performance or creates other kind of issues?

     

    And I tried to put that ForAll code into my If statement, but it throws many errors and I'm confused what I did wrong. (The idea is that clicking on a button should trigger a flow that uploads the files in the attachment control and when it's done, notifies the user.)

     

     

    If(ForAll(DetailsMachineUploadAttach.Attachment As FILE;
     'MLIProductionInstructions-Machine:CreateFolder+uploadimage'.Run(
     InputDetailsMachineID.Text;
     {
     contentBytes: FILE.Value;
     name: FILE.Name
     }
     
     ).status = "Completed";
     Notify(
     "Upload successful!";
     NotificationType.Success
     )
    )
    );;

     

     

     

    Screenshots of the errors:

    LisKr_0-1712823697285.png

    ⬆️it says "invalid number of arguments. got 3, expected 2" , "invalid number of arguments. got 1, expected 2 or more" and "invalid name. attachment is not recognized".

     

     

    LisKr_1-1712823800412.png

    ⬆️"incompatible type. Column "file:contentBytes" in the data source expects type blob, but you use type error."

    "function Run has invalid arguments"

    "invalid name. "FILE" isn't recognized".

     

     

    Did I just put the ForAll in the wrong place? Or am I just thinking too complicated about how to archieve my scenario?

  • WarrenBelz Profile Picture
    156,940 Most Valuable Professional on at

    @LisKr ,

    The issue is that you cannot really return a value from a multiple ForAll patch like that - theoretically, it will return only the last one, but I don't think even that would work as evidenced by your error. If you want to add multiple files, you probably need to disregard the error check and remove the returned value from the Flow.

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • LisKr Profile Picture
    304 on at

    Do I understand you correctly:

    It is only possible to upload multiple files OR do an action based on the return from the flow but only when uploading one file? Both together doesn't work? (I'm asking cause English is not my native language, so I want to make sure I understand what you want to tell me)

     

    The reason why I added that flow response and the if statement, is because when I upload a file to SP, the gallery that should show the files in that library only shows the "old" files without the recently uploaded one. And when I put a refresh (done with a variable) into the code directly after the flow run function, it refreshes while the flow is still running and so still doesn't show the newly added file. So I thought by adding the response and the notification based on it, it would force the app to wait until the flow is finished to execute the refresh.

    That's the whole purpose behind it. I also read about the possibility of archieving that with a timer control but that doesn't seem like a good practice to me, because the time is hardcoded and  if the flow should take longer than that estimated time, the refresh would still be too soon...

     

    Do you have another approach for that maybe? Or do you think it's better to just stick with uploading one file at a time? Would it maybe help, if I made screenshots from the UI of the app or if I posted the whole code with the refresh etc.?

  • WarrenBelz Profile Picture
    156,940 Most Valuable Professional on at

    @LisKr ,

    The issue is that it is several Flows that are being run in quick succession, and you cannot really set a variable to the entire result of that. A timer may be a better option for the refresh.

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • LisKr Profile Picture
    304 on at

    What a shame that there's no good build-in feature for waiting for the flow.

     

    The problem with the timer is, that sometimes the flow is completed after a few seconds, but the files are still not showing in the gallery after refreshing. In that case users have to wait another 10 seconds or so until it shows. So I'm not sure what to set the duration of the timer to, so that the users neither complain about long loading times (if I set the timer to 10 seconds) nor the files not showing up directly after uploading and refreshing (if I set it to i.e. 3 seconds)... It seems like every option just isn't very convenient, sadly.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 248 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 192 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 135

Last 30 days Overall leaderboard