Hi,
Been using for years some code from Youtuber Sean Young for storing attachments from powerapps to sharepoint using a flow.
In a new environment this flow, with the old powerapps trigger, will not be added to the app so I created a new with the new trigger.
The (text) input is a collection containg filenames and file contents as json of attachment control "images".
The resulting text in powerapps that the flow uses looks like this (i substituted ..... for a large part of the file content)
Column base64 will be used for the body of the eventual file.
[
{
"Name": "cat.jpeg",
"UniqueName": "86170723-8cat.jpeg",
"base64": "/9j/...../9k="
}
]
Since the original syntax for parse json from Sean Youngs example is not working (I get InvalidJSON error) I use this text to have powerautomate generate json syntax
The syntax looks ok but If I enter the same text testing I get the same error
InvalidJSON
{
"type": "array",
"items": {
"type": "object",
"properties": {
"Name": {
"type": "string"
},
"UniqueName": {
"type": "string"
},
"base64": {
"type": "string"
}
},
"required": [
"Name",
"UniqueName",
"base64"
]
}
}
The flow uses compose, parse jason, apply to each (save file).
In parse Jason I use
Powerapps code adapted to my situation:
;ClearCollect(
ColFiles
,ShowColumns(
AddColumns(
gAttachments.AllItems
,base64
,With(
{
varDemoFromAttachmentcontrol
:JSON(
Image4.Image
,JSONFormat.IncludeBinaryData
)
}
,Mid(
varDemoFromAttachmentcontrol
,Find(",",varDemoFromAttachmentcontrol)+1
,Len(varDemoFromAttachmentcontrol) - Find(",",varDemoFromAttachmentcontrol)-1
)
)
,UniqueName,Left(GUID(),10) & Name
,ThisImage,Image4.Image
)
,base64
,Name
,UniqueName
//;"ThisImage"
)
)
I see Sean did some editing of the file content so I also tried the unedited JSON of the attachment control image contents but same result.
Never mind I found a later video by Sean on how to deal with the new powerapps trigger v2