Author: Ahad Hamirani
Before using the Attachment Control PCF, ensure the following:
Helpful Documentation: How to Add a PCF to A Canvas App
Table(
{
DisplayName: ".xlsx",
FileType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
},
{
DisplayName: ".pdf",
FileType: "application/pdf"
},
{
DisplayName: ".jpeg",
FileType: "image/jpeg"
}
)
Table(
{
FileName: "example.pdf",
FileContent: "application/pdf"
}
)
In order to parse all files into a PowerApps collection you can use the code below:
Table(ParseJSON(AttachmentControl.Files))
Then you can simply access the files in the collection using code similar to below:
FileName : ThisItem.Value.name
FileContent : ThisItem.Value.content
With(
{w_flowResponse: getFiles.Run()},
ClearCollect(
col_DefaultFiles,
Table(
{
FileName: w_flowResponse.filename,
FileContent: w_flowResponse.filecontent
}
)
)
)
🗒️Note: The PCF CAN handle multiple default files being passed in as long as the table follows the schema below:
Table(
{
FileName: Sample.filename,
FileContent: Sample.filecontent
}
)
Since PCF Components are unable to use the PowerFx Reset Function we will have to use a toggle to "Reset" this PCF.
Purpose: The reason I have added a reset toggle is to provide makers the ability to "reset" this PCF to it's Default State.
Default State: The Default State
of this PCF is one where all user uploaded files are cleared and any default provided files are kept or restored.
Uses:
Clear Files:
This property can be used to clear all files within the attachment control (given that the default files are empty)
Restore Default Files:
This property can restore all default files. This can be handy if makers use the attacment control as part of a form and want to restore changes
🗒️Note: Setting this property to "true" will reset the control and keep it in reset mode, but in order to avoid any bugs please make sure to toggle the property off before using it again.
💡Suggestion: I would reccomend setting this property to the inverse of the visibilty of the control. Meaning when the control is hidden it gets reset and when it is visible the reset property is toggled off.
This is the intial version of this PCF and although I have used it in production and done testing it may contain bugs. If you encounter any issues or bugs feel free to let me know and I will try my best to address them.
Happy Developing!