Through my mendix frontend, I wish to upload a binary file to an external REST api.
This does not seem possible without jumping through many hoops, e.g. with the 'File Manager' widget, I must have a persistent entity of type System.FileDocument....this means I have to make this entity, populate it, then use it to send the file contents to the external API before finally deleting it.
This seems like it requires a number of microflows:
1. When I open the 'Upload' page, it seems I need to first have an empty instance of System.FileDocument on hand. So I need a microflow to create this. Since I want multiple users to upload potentially simultaneously, I suppose I need a 'specialisation' of System.FileDocument to relate an instance to a user?
2. Now I can show the data view for the FileDocument, I need to actually get the instance. I need a microflow here to make sure I get the one related to the current user
3. Now when the user finally clicks the confirmation button to actually do the upload, I need a microflow to get the contents of the FileDocument and make a POST request to the external API, then finally delete the FileDocument.
This seems both inefficient and a potential nightmare to maintain (it is a unnecessarily complex workflow for what is almost a one-liner in JS).
Is there any way to do this in a simpler manner (before resorting to a custom widget)?
1. You don't need a specialised FileDocument linked to each user. If you don't commit the file then you shouldn't need to delete it once upload is done. The MF is simple, with two actions Create Object FileDocument , then Show Page.
2. The DataView will already have your Newly created FileDocument as a context object, since you supplied it as a page parameter, so you don't need to fetch it again.
Add your 'SubmitToAPI' button to the same DataView and the file will be available as a parameter to your MF
3. You might (probably will) need to use the REST services module from the Appstore to add your file to the POST request (See RESTServices.post).