Guidance on attaching files to Questionnaire Respo...
# support
d
One step in our onboarding questionnaire is to have patients upload photo(s) of an injury. We have recently noticed that the uploaded photos are only visible for a short period of time. I believe this is b/c we are storing the signed url in the
valueAttachment
in the answer. This is coming directly from the
createAttachment
method. Below is some pseudo code for how we are doing photo upload:
Copy code
// Attachment Input
const attachment = await medplum.createAttachment({
  data: blob,
  contentType: asset.mimeType || 'application/octet-stream',
  filename: asset.fileName || 'attachment',
})

handleValueChange(attachment)

// QuestionnaireFormItem.tsx

case QuestionnaireItemType.attachment:
  formComponent = (
    <AttachmentInput
      defaultValue={defaultValue?.value}
      onChange={(newValue) => onChangeAnswer({ valueAttachment: newValue })}
    />
  )
break
Which results in this in the
answer
field for the item:
Copy code
"answer": [
  {
    "valueAttachment": {
      "contentType": "image/png",
      "url": "https://medplum-storage.mydomain.com/<aws-signature>",
      "title": "IMG_6374.png"
    }
  }
]
We are using our own component because this is a react native app, but looking at how the attachment works in
@medplum/react
this is effectively identical. So the question is: How should we be saving attachments so that they are visible in the future? Also, we are self-hosting and I posted a somewhat similar issue last week around invalid reference to the Binary when uploading a bot. I'm kinda wondering if this is a server configuration issue and not a UI issue
i
@Doug DeBold, instead of storing the signed URL, you should store a reference to the Binary resource that createAttachment creates. Here's how to fix it:
Copy code
// When creating the attachment
const attachment = await medplum.createAttachment({
  data: blob,
  contentType: asset.mimeType || 'application/octet-stream',
  filename: asset.fileName || 'attachment',
});

// Instead of using the attachment directly, create a reference
const attachmentReference = {
  contentType: attachment.contentType,
  url: `Binary/${attachment.id}`, // Reference to the Binary resource
  title: attachment.title,
};

handleValueChange(attachmentReference);
And regarding the images not being visible after a while, you are correct that it is because you are referencing the signed urls
d
Great thank you for confirming. Do you think then that the QuestionnaireFormItem.tsx needs to be updated b/c I believe it is just directly storing the raw attachment and not referecing the binary https://github.com/medplum/medplum/blob/main/packages/react/src/QuestionnaireForm/QuestionnaireFormItem.tsx#L212
59 Views