Cannot `medplum.delete(attachment.url)` in self-ho...
# support
l
I'm trying to delete an attachment with medplum.delete(attachment.url) but I repeatedly get 404 error - Not found. However, I can download the attachment just fine using the same url. The attachment is created in a self-hosted environment with the code below. As mentioned, I can download it but cannot delete it.
Copy code
const options: CreateBinaryOptions = {
          contentType: 'application/json',
          filename: 'manifest.json',
          data: JSON.stringify(manifest, null, 0),
        };

const attachment = await medplum.createAttachment(options);
r
Hi @lane - Binary files are handled a bit differently than other data
You'll see that these get translated into
storage.medplum...
urls, whcih can't immediately be used with
deleteResource
You'll see a url like;
https://storage.medplum.com/binary/<id>/<version>?....
You'll want to extract the
<id>
from this url, and then call
medplum.deleteResource('Binary', <id>)
l
Thanks. But I am not using deleteResource. I am using delete. This is an Attachment with a title, url, and data and no resourceType. Not a Binary resource with resourceType, meta, etc. I don't have an id to use, only a signed url 😦
r
When you create an attachment with a url, medplum, it should automatically create a binary resource on your behalf
storage....
url would correspond to a Binary resource
Binary resources aren't searchable, but if you navigate to the specifc Binary resource in the Medplum App (app.medplum.com/Binary/id) you should be able to see it
l
So, if I understand correctly, you are maybe suggesting that I should find a resourceType and id on what I download?
r
yes, I think our server shoudl have created it for you
you can parse that signed url to find the appropriate
Binary
resource
l
Hmmm... I do not find this. Checking again (this is, btw, an attachment in the content field of a Library resource. One moment, please ...
No. My content array is a list of attachments:
Copy code
{
      "url": "https://customer.my-elixir.local/storage/019797d5-571a-73e9-9ef2-90d5461dc3e1/019797d5-571a-73e9-9ef2-973b2f658a93?Expires=1750700271640&Signature=X43SO2pnoSR83mp6K76ZYXdQXf%2BgYB%2FZlX2VZUCpM3fZ22TgkYFk6NM7kLL3Bhw03iOz0zwMlOXc217cqvBEjYqNh5O2uKOIcAQbR2%2BM5UQX%2FesU0Gx%2BDNxdy0axBMk%2BETw9oNgfacoOIDv8sQOpaf1SonF0uVtHF7JcoTGw4UNNqbX5eRoFeyoHET40lpSJyP4JGGTNpVj4sjR%2F38713K%2BFF%2BhwL7Vc7A9StjgW3Ubjq%2BZDkn3Xy4YvcmXkeLzuAEfNLbA2UuKZxISURsensjGnLtnklkn01EBpEFqHql72WRD36rfd%2F%2BT1Ztf%2FBG8YiwEX96QSHOzvqa5Ph91vzg%3D%3D",
      "title": "esbuild-script.mjs"
    },
And, as mentioned, I can download the underlying file from the link. I just cannot delete it.
r
is there any resource at
Binary/019797d5-571a-73e9-9ef2-90d5461dc3e1
?
l
Checking ...
Yay! There is! Now I can figure it out. Thanks, so much for your time!
156 Views