Create a file
You can create a file in OneDrive from a solution in the . Use the media-field component in a form to upload a file or image, then use the OneDrive Data Provider, its create method. and required properties for successful file creation.
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: create
To create 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.
- The create method does not allow you to create a file with a filename that already exists and an error will occur. To ensure the cause of the error is understood recommends you build in logic using a modal to show a message that the filename is already in use.
- A new file is created even when an id is specified.
- 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 for creating an invoice in the myfiles directory of OneDrive.
Example of a modal message that can be displayed when creating a file with an existing file name. The full code snippet is shown: