Skip to content

Feature request: option to upload source image via http request #1332

Closed

Description

@pkruithof

First of all, thanks for the project, it's really cool!

I was wondering if it could be considered to upload the source image with the http request? Right now you have to specify an image source, in my case that would be Google Cloud Storage. However I just want to pre-process the image before uploading it there. I could post-process it after uploading of course but it seems inefficient to upload twice. The data costs for GCS are something to keep in mind here.

What would help is if you could do something like this:

curl -XPOST imgproxy:7700/%processing_options/upload --data-binary @file

Activity

  1. DarthSim commented on Sep 25, 2024

    @DarthSim
    Member

    Hey @pkruithof!

    I think this is the wrong approach for imgproxy and imgproxy is the wrong tool for this approach.

    This is the wrong approach for imgproxy

    imgproxy is a tool for post-processing. By post-processing I mean the approach where you store only the original image and generate its variants on-demand without storing them anywhere except the cache.

    The approach where you generate image variants on upload is called pre-processing. While you can technically use imgproxy for this approach, imgproxy is not designed for it.

    imgproxy is the wrong tool for this approach

    First of all, imgproxy is an HTTP server. This is a layer that you don't need for the pre-processing approach. It's easier and more effective to use image-processing libraries or tools directly.

    I could post-process it after uploading of course but it seems inefficient to upload twice

    It's always a good idea to store the original image even if you also store its variants since you may need new variants in the future

    The data costs for GCS are something to keep in mind here

    You can store up to 50GB in GCS for $1. If your project doesn't generate $1 per 50GB of stored data, I believe it's a way bigger problem.

  2. pkruithof commented on Sep 27, 2024

    @pkruithof
    Author

    Fair points, can't really argue with any of them 😄

    The reason I used Imgproxy was as an alternative to Imaginary, which seems to be not that well maintained unfortunately. But I guess I'll stick to that and hope it's not really abandoned.

    You can store up to 50GB in GCS for $1. If your project doesn't generate $1 per 50GB of stored data, I believe it's a way bigger problem.

    Storage costs are not my worry here, it's the outgoing traffic that can get you, as I've discovered in the past 😉

  3. DarthSim commented on Sep 30, 2024

    @DarthSim
    Member

    Traffic between GCS and other Google Cloud services (like GCR) is actually free

  4. jannes-io commented on Oct 18, 2024

    @jannes-io

    @DarthSim I would also like the ability to send the source image along with the request. Consider the following use-case:

    We have tons of small kubernetes pods that all require image processing. Currently each container has its own image processing through Imagemagick (PHPThumb), other than that, they're just very simple PHP websites. So this image processing is currently the largest part of our process, and all of our containers have to be sized substantially larger to accommodate for this peak usage.

    We would like to run 1 imgproxy pod per cluster, so all containers could offload the image processing to that pod, and we can downsize all of them to a more appropriate scale (saving a lot of $$$ in doing so).

    We always download the original image to the container, compute a checksum, and then use that checksum to check in our cache to see if it has been resized before, and return a cache version instead. So we always have the original source already in-memory of our application.

    On imgproxy's side I don't really see anything that would violate your KISS principle. You already have local images so we're halfway there already?

  5. pkruithof commented on Oct 18, 2024

    @pkruithof
    Author

    This was pretty much our use case as well. We wanted to use a local volume initially, because you can point Imgproxy to that. However using shared writeable volumes in K8S is notoriously difficult, so this wasn't really an option. The other option was to have each pod have Imgproxy as a sidecar, like you described. And like you described, we had the same hesitation against using it that way.

    Traffic between GCS and other Google Cloud services (like GCR) is actually free

    Unless not all services are in the same region, which is the case for us. I understand that this is more of an "us problem", but regardless, it's not always free. Like I said, we have had some experience with this.

  6. jannes-io commented on Oct 18, 2024

    @jannes-io

    However using shared writeable volumes in K8S is notoriously difficult, so this wasn't really an option.

    Yeah, the only option you have is Filestore (when using GKE), which is quite pricey considering the smallest size is 1TB. But even if it was a viable solution, we already have the image in-memory of our application. Having to write it to a shared volume which is then read by imgproxy adds unnecessary I/O and complexity on the application's side.

  7. DarthSim commented on Oct 18, 2024

    @DarthSim
    Member

    We always download the original image to the container, compute a checksum, and then use that checksum to check in our cache to see if it has been resized before, and return a cache version instead. So we always have the original source already in-memory of our application.

    It seems to me like this is the actual problem. I ain't your architect, but:

    1. Nowadays, every (or at least almost every) storage allows you to request file hashsum/ETag/etc. Sometimes this requires an API call, sometimes it's just a HEAD request. So you most probably don't really need to download an image.

    2. There's an important rule in asset management: don't change an asset's content without changing its name, this inevitably will cause problems with caching. The need to download the image and calculate its checksum is the result of breaking this rule. Otherwise, you could've used the filename as a cache key.

    However, I understand I'm taking like Captain Hindsight, and it's too late to change things.

    On imgproxy's side I don't really see anything that would violate your KISS principle. You already have local images so we're halfway there already?

    There are a couple of problems I see right away:

    1. imgproxy's image downloading flow is designed to use only URLs to locate the source image. Using the request body as an image source would require passing it somehow to the downloading flow.

    2. POST requests can't be easily signed which makes them pretty much insecure. I guess it's not a problem for you since you probably don't expose imgproxy to the world, yet still.

    However, both problems can be solved in some way. POST requests can be disabled by default and called insecure. Users should only enable them at their own risk.

    As for request bodies, I see the following approach possible:

    1. POST requests don't require a source image URL. If one is present, it is ignored.

    2. When imgproxy receives a post request, it puts the request's body to a map with a random key. Then it redefines imageURL to post://<key>.

    3. The post:// scheme RoundTripper fetches the body from the map and uses it as its response body.

    Though I can eventually try this approach, I can't give you any time estimations. And I can't guarantee that this won't be a Pro-only feature. However, PRs are always welcome.

  8. jannes-io commented on Oct 18, 2024

    @jannes-io

    However, I understand I'm taking like Captain Hindsight, and it's too late to change things.

    Yes, dealing with a 15 year old codebase that has always used PHPThumb in the past, the links are scattered all over the place across multiple vendors, 3rd party integrations, external API users,... there's no way of going back now. We've had to hollow out PHPThumb and transform all the requests from PHPThumb's parameters to imgproxy's so our endpoint would remain entirely backwards compatible.

    But besides just legacy code, there seems to be a pretty solid argument to have an image processor behind a HTTP layer to use as a microservice for pre/post processing. Cloud functions/AWS Lambda have their own issues with latency, unreliable pricing, vendor lock-in,... Being able to use the same microservice for on-demand thumbnails and pre/post processing would really simplify the implementation side of things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions