diff --git a/src/modules/form/form.service.ts b/src/modules/form/form.service.ts index 5f4d901..76458c1 100644 --- a/src/modules/form/form.service.ts +++ b/src/modules/form/form.service.ts @@ -8,7 +8,7 @@ import { PROGRAM as ProgramMessages, } from '../../common/messages'; // eslint-disable-next-line @typescript-eslint/no-var-requires -const fs = require('fs'); +import fs from 'fs'; import parser from 'xml2json'; import { FormMediaUploadStatus, FormUploadStatus } from './form.types'; @@ -79,6 +79,7 @@ export class FormService { await this.login(); if (mediaFiles && mediaFiles.length > 0) { const mediaUploadResult = await this.uploadFormMediaFiles(mediaFiles); + this.logger.log(`Uploaded media files data: ${JSON.stringify(mediaUploadResult.data)}`); if (mediaUploadResult.error || !mediaUploadResult.data) { this.logger.error(`FormService::uploadForm: Media Files upload failed!`); throw new ServiceUnavailableException(`Media upload failed! Reason: ${mediaUploadResult.error}`); @@ -164,8 +165,9 @@ export class FormService { const promises: any = []; mediaFiles.forEach((mediaFile: Express.Multer.File) => { + fs.copyFileSync(mediaFile.path, `${mediaFile.destination}/${mediaFile.originalname}`); const formData = new FormData(); - const fileToUpload = fs.createReadStream(mediaFile.path); + const fileToUpload = fs.createReadStream(`${mediaFile.destination}/${mediaFile.originalname}`); formData.append('file', fileToUpload, mediaFile.originalname); const requestOptions = { @@ -222,7 +224,7 @@ export class FormService { try { let data = fs.readFileSync(formFile.path, 'utf-8'); uploadedMediaNames.forEach((value: string, key: string) => { - data = data.replaceAll(`{${key}}`, value); + data = data.replace(`{${key}}`, value); }); fs.writeFileSync(formFile.path, data); return '';