diff --git a/src/components/renderer/file-upload.vue b/src/components/renderer/file-upload.vue index 1a3acf22a..c7d43f134 100644 --- a/src/components/renderer/file-upload.vue +++ b/src/components/renderer/file-upload.vue @@ -99,6 +99,10 @@ export default { this.removeDefaultClasses(); }, mounted() { + if (this.value) { + this.fetchFiles(); + } + this.$root.$on('set-upload-data-name', (recordList, index, id) => this.listenRecordList(recordList, index, id)); @@ -621,6 +625,28 @@ export default { : null; } }, + async fetchFiles() { + const fileIds = Array.isArray(this.value) ? this.value : [this.value]; + + const fetchPromises = fileIds.map(async (file) => { + const id = file?.file ?? file; + const endpoint = `files/${id}`; + try { + const response = await ProcessMaker.apiClient.get(endpoint); + if (response?.data) { + const fileExists = this.files.some(existingFile => existingFile.id === response.data.id); + // Check if the file already exists in the list before adding it. + if (!fileExists) { + this.files.push(response.data); + } + } + } catch (error) { + console.error(`Failed to fetch file ${id}`, error); + } + }); + + return await Promise.all(fetchPromises); + }, }, };