Unable to get the File name

Hi @Platform_Team !

I’m not getting the file name when posting an attachment to the server. The request I’m sending is:

export function createAttachment(patientUuid: string, file: UploadedFile) {
  const formData = new FormData();
  const emptyFile = new File([''], file.fileName);
  formData.append('fileCaption', file.fileDescription);
  formData.append('patient', patientUuid);
  formData.append('file', emptyFile);
  formData.append('base64Content', file.fileContent);
  console.log('saving file', file);

  return openmrsFetch(`${attachmentUrl}`, {
    method: 'POST',
    body: formData,
  });
}

I’m getting the fileCaption in form of comment from the response, but I’m not getting the file name that I’m sending. Attachment url: /ws/rest/v1/attachment Thank you.

Hi @vasharma05, you could simply keep the original file name in a variable for later use or alternatively make another rest GET call for the attachment(/ws/rest/v1/attachment/<attachment-uuid>/bytes) where you’d then extract the saved name from the File-Name Header parameter.

1 Like