Update/Save a file
Files often change and need to be edited or updated with additional information; for example, team members can collaborate and edit and update a contract proposal. You can update an existing file in OneDrive from a solution in the . Use the media-field component in a form to upload the updated file or image, then use the OneDrive Data Provider, its update or save method, and required properties. The existing file in OneDrive will be updated.
The following properties are required in the YAML:
- file - reference the physical file
- fileName - add the file name with the extension, e.g. Invoice.pdf
- entity- file path in OneDrive
- tokenType - OAuth token credentials name
- method: update
To upload a file use the media-field component to select the file. Use the image, or any property in the media-field component to specify the mediaType.
- When no id is provided, a new record is created if it is not a duplicate filename
- Important: When updating a file and changing the filename, if the new name is the same as an existing file name, the amended file is saved to the existing file with no warning that the file will be overwritten
- The filename is crucial in determining if the item must be saved/updated or whether a new file should be created
- When only updating the file, it uses the id and the file and then saves/updates as requested
- Any change to the filename executes a create method, even if the id is specified and a new file is added to OneDrive
- Updating/saving an existing file by only changing the file, saves the file against the original record
- recommends you build in logic using a modal to show a message that the file will be overwritten
- Using the method: save will create a new file if the filename does not exist, otherwise the save will function as an update method
- A delay or time lag of several minutes could be experienced when files are syncing between the device and OneDrive
The code below provides an example of a list of invoices in the myfiles directory of OneDrive. When selecting the file in the dropdown list, the file name is displayed and the media picker is used to uploade the updated file. Pressing the Update Invoice button updates the file on OneDrive.
Example of a modal message that can be displayed when overwriting an existing file.