Hello
I am building a custom workspace view (previously known as Context app) at the moment.
The user needs to pick a ZIP file to upload to the server.
I have stumbled across a few different components that I could use, but I am not sure what is the best/right one to use and could do with some guidance please
Using <umb-input-upload-field></umb-input-upload-field> seems to handle some stuff for me where the file is POSTβd to an API endpoint to upload it as a temporary file using the Management API /umbraco/management/api/v1/temporary-file
This file then ends up on disk at umbraco\Data\TEMP\TemporaryFile with a GUID as a folder name and inside is my file along with a file called .metadata which contains JSON with some expiry date which I assume the server will come along at that time and remove the file/s.
However I have not yet figured out, how I can be notified with an event from using this component has finished uploading the file, in order for me to then call a C# API myself from JS where I assume I would then need to persist the file myself?
Thoughts?
So am I using the right component out of these above?
Is using this component and the temporary-file thing the right approach?
I will iterate here what Warren and I discussed on Slack:
The <umb-input-upload-field> is a good component to use. You will have to listen to its change event and then find its temporary file from the target: (event.target as UmbInputUploadFieldElement).temporaryFile.
You will then have to send the GUID of the temporary file somewhere to an API controller, which can move the temporary file into its final location. The Backoffice itself does this for its types typically on Save events, so that temporary files that end up not being used will be deleted after a certain time.
#onUploadChange(event: Event) {
// Fires when upload has been saved as temp file
// And also if the file is cleared
const uploaderEl = event.target as UmbInputUploadFieldElement;
const uploadValue = uploaderEl.value;
const tempFile = uploaderEl.temporaryFile;
console.log('[CHANGE] Upload .value:', uploadValue);
console.log('[CHANGE] Upload .temporaryFile:', tempFile);
// Call C# API to Persist & Save file and store entry in DB
}
Will update the thread once I have done the work on the server dealing with the file.