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 / Upload 1gb file via AP...
Power Apps
Unanswered

Upload 1gb file via API call (no flow) using UPLOAD SESSION + CHUNK

(3) ShareShare
ReportReport
Posted on by 14
Hi. I am building an app canvas in power apps. In this app there are the default Sharepoint FileAttachmentControl and a Button.
I am looking for something like this tutorial: Upload Large Files.
In the OnSelect property of the Button component, I structured my code into two parts.
- In the first part: I create the Upload Session.
- In the second part: I split my file into chunks and upload those chunks to the URL generated in the first part.
//OnSelect: 1st STEP
Set(
        uploadSessionResult;
         'HTTPwithMicrosoftEntraID(preautorizzato)'.InvokeHttp(
             "POST";
            "https://graph.microsoft.com/v1.0/sites/" & siteId & "/drives/" & driveId & "/root:/" & folderName & "/" & fileName & ":/createUploadSession";
            {
                ContentType: "application/json"
            ;
            body: "{""item"": {""@microsoft.graph.conflictBehavior"": ""replace"", ""name"": ""m24_l1.pdf""}}"
            }
        )
    )
Set( uploadUrl; Text(uploadSessionResult.uploadUrl) );;
This 1st part works fine.

Then I have to :
1) read the attachment size
This tutorial  worked fine for me.  I only changed the SizeLabel property cause I don't need to work with  "MB" but  "bytes"
(cause the Chunk Maximum Size is 327680 bytes)
 
Label: ((Len(varJSON) - 814) / 1370000  )*1024*1024
2) extract the attachment binary data 
//OnSelect: 2nd STEP
Set(
    BinaryData;
    JSON(ImgFile.Image; JSONFormat.IncludeBinaryData)
);;
 
Set(
    varBase64Only;
    Left(
        Index(
            Split(BinaryData; "base64,");
            2
        ).Value;
        Len(
            Index(
                Split(BinaryData; "base64,");
                2
            ).Value
        ) - 1
    )
);;
3) Calculate the number of Chunks for the current Attachment
//OnSelect: 3rd STEP
Set( varFileSize; Value(SizeLabel.Text));;
Set( ChunkSize; 327680);; 
Set(totalChunks; RoundUp(varFileSize / ChunkSize; 0));;
4) Divide the file into chunks and upload every single chunk
 
          //OnSelect: Last STEP
ClearCollect(ChunkTable;                     
    ForAll(
        Sequence(totalChunks);
        {
            startByte: (Value - 1) * ChunkSize;
            endByte: Min(Value * ChunkSize - 1; varFileSize - 1)
        }
    )
);;
 
ForAll(
    ChunkTable;
    With( 
         {
            chunkData: Mid(varBase64Only; ThisRecord.startByte + 1; ThisRecord.endByte - ThisRecord.startByte + 1);
            requestHeaders: Table(
    {key: "Content-Length"; value: Text(ThisRecord.endByte - ThisRecord.startByte + 1) };
    {key: "Content-Range"; value: "bytes " & ThisRecord.startByte & "-" & ThisRecord.endByte & "/" & varFileSize}
                       
         };
     'HTTPwithMicrosoftEntraID(preautorizzato)'.InvokeHttp("PUT"; uploadUrl;
           {headers: requestHeaders; body: chunkData}
       )    
     )
    );;

Result: PUTrequest ends with  ONE OR MORE ERRORS OCCURRED


Debug:  I noticed a strange behaviour and I think is the PUTrequest's failing reason.
ChunkTable is ok, but when I try to print Content-range  in that ForAll iteration , It occurs that:
varFileSize has the default value (something like -630) .
This happens during the 1st and the 2nd iteration of that ForAll ; after that, varFileSize has the right value.

PS: I am using the european settings , so  "comma" is replaced by ";"  and "every code line is closed by  ;; " 



 
Categories:
I have the same question (0)
  • ApiTrader Profile Picture
    174 on at
    I struggle also with this endpoint, did you solve your problem? My error recomment to check my internet connection. 
     
        'HTTPwithMicrosoftEntraID(preauthorized)'.InvokeHttp(
            "PUT",
            'HTTPwithMicrosoftEntraID(preauthorized)'.InvokeHttp(
                "POST",
                "https://graph.microsoft.com/v1.0/me/drive/items/root:/Folder/AppCache/BillingTemplate.docx:/createUploadSession",
                {
                    headers: Table(
                        {
                            key: "Content-Type",
                            value: "application/json"
                        }
                    ),
                    body: JSON(
                        {
                            item: {
                                '@microsoft.graph.conflictBehavior': "rename",
                                description: "description",
                                driveItemSource: {'@odata.type': "microsoft.graph.driveItemSource"},
                                name: "BillingTemplate.docx"
                            },
                            deferCommit: true
                        },
                        JSONFormat.IncludeBinaryData
                    )
                }
            ).uploadUrl,
            {body: varBase64Only}
        )
  • D1d1 Profile Picture
    4 on at
    Hello,
     
    I wanted to ask if you have found a solution to your problem. I am also looking to realize a chunked upload from PowerApps.
     
    Thanks
  • AZ-10040037-0 Profile Picture
    4 on at
    For people who have been struggling in uploading large size files on Power Apps (canvas apps).
     
    Firstly Power Apps and Power Automate alone or together can be used to upload files to a data source like SharePoint document library. However there is a file size limitation on how many bytes can be transferred using Power Apps or Power Automate.
     
    There are two ways to upload files to a data source like SharePoint document library.
    1. Using the HttpRequest method of Office365Groups connector.
    2. Using the InvokeHttp method of HTTPwithMicrosoftEntraID(preauthorized) connector
    We have observed files up to 200Mb got uploaded to SharePoint document library via graph api using HttpRequest method of Office365Groups connector. However it does not work for large size files (>200Mb) due to timeout error. It also depends on the internet connection speed.
     
    For InvokeHttp method of HTTPwithMicrosoftEntraID(preauthorized) connector, there are some known issues and limitations on using it.
     
     
    This simply means sending the base64 chunks is not possible as this method would convert the chunks again into base64 which would result in file corruption.
     
    There is a well known technique to get base64 string of a file by using the image control and set it to the value of the attachment control. The problem here is that when we upload a file greater than 500Mb, the whole application just crash with out of memory error. This is due to the JSON function  JSON(ImgFile.Image; JSONFormat.IncludeBinaryData) that cannot handle that large amount of binary data.
     
     
    In a nutshell, Power Apps is a light weight Rapid Application Development platform to develop the apps with low code. It is not designed to do heavy lifting.

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 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard