Updating resources with attachments hard-codes lin...
# support
d
Hi there, we have once again encountered this issue and while I understand how to fix this case, I would like to talk about how to prevent this in the future. The issue we are having is that when we attach a file to a resource, for example an image being attached to a
Communication
, if we update that resource again, it is VERY easy to replace the link to the Binary with a hard-coded signed URL pointing. This then quickly expires and makes the image unavailable for viewing. As far as I can tell, this applies to every single resource that may have a binary attached to it. How to replicate: 1. Create a resource with an attached Binary 2. Do an full update of the resource, e.g.
medplum.updateResource(...communication, sent: new Date())
3. Notice that
payload.contentAttachement
will have changed even through it wasn't updated This foot-gun has bit us at least 3 times now. Maybe we are doing something wrong, but aside from banning the use of
updateResource
I really don't see how to prevent this. Any ideas?
d
Hi @Doug DeBold, sorry you've ran into this a few times over! Please correct me if I'm wrong, but it sounds like you're looking to do a partial update - since you're not expecting the
Communication.payload
value to change. In this case, I'd suggest using
patchResource()
instead, where instead of:
Copy code
tsx
medplum.updateResource(...communication, sent: new Date())
You’d do something like:
Copy code
tsx
await medplum.patchResource('Communication', communication.id, [
  { op: 'replace', path: '/sent', value: new Date().toISOString() }
]);
The
patchResource()
command will ensure that only the specified fields on the resource are updated. If the
Communication.payload
needs to remain untouched, then leave it out of the array of operations. Please let me know if this solves your issue, or if you have anything you’d like to follow up on! Ref: https://www.medplum.com/docs/sdk/core.medplumclient.patchresource
d
Yes the solution is to use
patchResource()
. But sometimes when dealing with nested data
patch
is really hard to use/impossible and you have to fall back to
updateResource()
. The fact that using
updateResource()
if there's an attachment will effectively kill the attachment feels like a big foot-gun that needs to be called out or fixed. Is there appetite for some sort of fix here?
20 Views