2. Misuse of either Patch function or attachment control: If we send the base64 string directly to SharePoint without converting it to a file content type, SharePoint may save an invalid file.
Let's go for two steps solution:
Step-1: Please use JSON and Mid functions to extract the base64 content properly: As the Camera control's Photo property returns a data URI like "data:image/png;base64,iVBORw0KGgoAAAANS...", we need to remove the prefix before sending to destination (SP).
Step-2: Please use Patch with Attachments field properly: Let's convert the base64 string to binary data and send it as an attachment.
I am assuming Save/Upload button is used and on it's OnSelect event we can formulate this below code:
//--Let's extract base64 string without prefix
Set(
varImageBase64,
Mid(
Camera1.Photo,
Find("base64,", Camera1.Photo) + 7,
Len(Camera1.Photo)
)
);
//--Build a collection with the attachment content in binary format
ClearCollect(
colAttachments,
{
Name: "CapturedImage.png",
ContentBytes: JSON(varImageBase64, JSONFormat.IncludeBinaryData)
}
);
//--Submit the form or patch the item with colAttachments as the attachment source
SubmitForm(Form1);
varImageBase64 stores the pure base64 string without the "data:image/png;base64," prefix.
colAttachments is a collection with one record containing the file name and the binary content converted from base64.
- Lastly, it is assumed that the form’s attachment control should be bound to
colAttachments or we can use colAttachments in a Patch function to upload the image.
If it helps - here is the Patch function if you don't bind the control:
Patch(
'SPList',
Defaults('SPList'),
{
Title: "ItemTitle", // other fields as needed
Attachments: Table(
{
Name: "CapturedImage.png",
ContentBytes: JSON(
Mid(Camera1.Photo, Find("base64,", Camera1.Photo) + 7, Len(Camera1.Photo)),
JSONFormat.IncludeBinaryData
)
}
)
}
)
I am sure some clues I tried to give. If these clues help to resolve the issue brought you by here, please don't forget to check the box Does this answer your question? At the same time, I am pretty sure you have liked the response!