-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get binary data with image/* Accept header that is used by browsers for img tags #1077
Comments
Regardless of whether it's a good idea to serve images from the database, and many people advise against it, this does seem like a postgrest bug. Your Accept header included |
It would indeed be a very bad idea to serve every image for every user from the database, but I'm going to put a CDN in front of it, so it'll be every image just once within the expiration period from the database and the rest from the CDN.
Would be great if it could. I'm sorry to say I have zero experience in Haskell. Otherwise, I'd give it a go. I'd need to find some free time first to learn the language.
|
Oops, I missed that in the first message. Seems fine then. Stored procedures allow you to set a sql variable btw that allows you to set response headers, so you can set the caching the way you need to.
I'll look into it over the weekend, it may not be so hard to fix. |
Excellent
You rock! Btw, I'm using Postgrest on Heroku deployed with the buildpack. |
I'm now using Cloudfront as a CDN in front of the image api that I configured to change the accept header. So the img tag causes a request to Cloudfront with Accept: image/*, etc. Cloudfront than alters it to application/octet-stream and calls the api that serves the binary. So, I'm good now. Functionally this is not a requirement for me anymore... |
Glad you found a way to integrate it with the CDN. I was thinking about this feature more and running into a difficulty for the general solution. If a client specifies |
I was looking into the Accept header that different browsers are using for the img tag. For example when Safari requests an image, there is:
When Safari requests a stylesheet, there is
So I suppose the occurrence of any of these literal values |
Would this be an acceptable compromise? If so, I'd try to come up with a pull request... |
@witsch Yes, I think that would be good. PR whenever you're ready. |
Solved by #1349. Now it's possible to add this config option:
And a request with |
I am also facing the same issue .. how I need to set the img inside the img src tag ? I have tested my api it is returning the data in the form of byte but when I am calling inside the img tag it is give me the empty response. Can some one help me how can I return the image as a response and display it in the img tag |
Thanks to #802 we can get binary output using the
Accept: application/octet-stream
header. Works fine. I can fetch my binary, which is an image using Postman:But now, I want to get that image in an img tag like so:
<img src="http://server:3000/images?select=binary_data&id=eq.f6deb9ff-839f-426c-baa0-0f05ebbab691">
But the result is a 200 with an empty response. Probably because the Accept header is not
application/octet-stream
, butimage/webp,image/apng,image/*,*/*;q=0.8
I know I can use a base64 data img src and I know about the pros and cons. In need the url's as img src. Later I'll setup a CDN to cache the images from the api. But for now;
What can I do to get binary output from the api with the image/* header that the browser is currently sending along with the img request?
The text was updated successfully, but these errors were encountered: