Sometimes we need to use Graph API to upload files, normally the API has limitation in file size for a single request.
Since we have to pass binary object in Graph API request body, we need to find a way to split binary object into small pieces and upload it one by one.
In Logic App, when we print a binary object, it will be converted as base64 string and also we have an expression to convert from base64 to binary (https://docs.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference#base64tobinary).
The alternative way is that we can simply use “Substring” expression to take partial of the base64 string and convert it back to binary.
As we all know, the base64 encode use 6 bits as one character while normally one character should be 8 bits, which means we can calculate the length of the base64 string based on the binary length.
The length of base64 string can be simply calculated as (binary length)/3*4, there are some expectations for the length calculation, but we will not experience in our scenario.
The only thing we need to take care of is the length of split binary length in bytes must can be mod by 3 which we can avoid split the base64 string in middle of the character.
1.In Logic App, I have a blob which is 2.1MB, and I would like to split it to 2 pieces (1MB and the rest).
2.So for getting the first part (1MB), the actual binary length should be 999,999 bytes, after the calculation, the length of the partial base64 string will be 1,333,332 bytes.
3.After we get the partial base64 string, we can convert it back to binary and pass it in Graph API.
4.Do the same for the rest part. In real scenario, it should be an “Until” loop for the process. This sample just for verify the mechanism.