Does SharePoint SPFx support pre/post-processing files on upload and download?

Jon Blum 1 Reputation point
2026-10-19T05:54:05.2133333+00:00

Working on integrating a system into SharePoint, and I'm not sure what's the best way to proceed with the design and implementation.

The clients want to ensure that any time an XML file is uploaded through the web app, some of the data gets encrypted in the file at upload time. Similarly, on download, the data blob is decrypted and passed on (and the file is saved with the decrypted blob stripped out).

On a quick look through SPFx extensions, it looks like a ListView Command Set extension might do the job -- but I need to know whether it's possible to intervene before the client file is uploaded, as opposed to after it's present on the server. I can work out how to create a custom upload command, which modifies the file and then handles the upload through the API -- but is there any way of intercepting a drag-and-drop upload before it happens, to handle it that way? Or would I have to add another extension to detect that they've uploaded the file (possibly using Power Automate), immediately process it, and save the changed version? Similarly, would I need a custom download command?

Microsoft 365 and Office | SharePoint | Development
0 comments No comments

2 answers

Sort by: Newest
  1. 1990Quebec 0 Reputation points
    2026-10-19T14:09:21.6666667+00:00

    I think Microsoft has a built-in way to do this. It's called Purview and I believe that you can configure it to encrypt files automatically during upload and decrypt them during download?

    Was this answer helpful?

    0 comments No comments

  2. Ana Le 2,960 Reputation points Independent Advisor
    2026-10-19T06:15:46.23+00:00

    Hi,

    If you are using SharePoint Online’s modern document library, SPFx supports building your own upload/download experience, but it does not provide a documented, supported hook for transforming file contents within the built-in Upload, drag-and-drop, or Download operations.

    A ListView Command Set can launch your custom action through onExecute(). List-view state-change events are not before-upload events. Also, onListViewUpdated() is deprecated; Microsoft now recommends context.listView.listViewStateChangedEvent for observing list-view state changes.

    For your requirements, I would consider the following design:

    1/ Process the XML before uploading through your own interface.

    Your custom command can open a file picker or a dialog containing your own drag-and-drop area. Your code can then process the XML and upload the transformed file through an API.

    This supports drag-and-drop within your component, but does not intercept SharePoint’s native drop area. I would avoid attaching handlers to SharePoint’s internal page elements: Microsoft explicitly states that the page DOM is not an API and that dependencies on its structure can break.

    2/ Use Power Automate or webhooks only if processing after storage is acceptable.

    You do not need another SPFx extension for this. A flow or backend service can detect a new file, retrieve its contents, process it, and save an updated copy.

    However, SharePoint webhooks are asynchronous, and Power Automate’s file-created trigger runs after the file exists. Therefore, neither approach guarantees encryption before the original XML reaches SharePoint. If versioning is enabled, replacing the file may also leave the original content in an earlier version.

    If overwrites of existing files must be processed too, a creation-only trigger is insufficient. An update-aware implementation also needs to prevent its own changes from repeatedly triggering processing.

    3/ Provide a custom download/export action.

    That action can retrieve the stored XML, perform the authorized decryption, and generate the required output. It will apply only to downloads made through your custom route; it will not transform downloads made through SharePoint’s built-in Download action or other clients.

    If processing must be mandatory, custom buttons alone are insufficient. My recommendation would be a controlled backend service that validates requests and processes the files, with permissions preventing users from uploading directly to the destination library. The backend would need its own appropriately scoped access; the SPFx interface would call that service. Hiding the standard Upload button would not enforce this requirement.

    Finally, when you say “the file is saved with the decrypted blob stripped out,” do you mean the downloaded copy or the original stored in SharePoint? Updating the stored original would be a separate operation requiring concurrency and failure handling.

    Microsoft references:

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.