pedestal

emccue 2020-10-01T06:34:00.032300Z

Probably a decently common problem

emccue 2020-10-01T06:34:03.032500Z

emccue 2020-10-01T06:34:07.032900Z

I have some images in s3

emccue 2020-10-01T06:34:25.033300Z

and I want to send them to the user

emccue 2020-10-01T06:34:49.033400Z

emccue 2020-10-01T06:35:00.034100Z

right now I have a basic handler that finds the right file

emccue 2020-10-01T06:35:43.034300Z

emccue 2020-10-01T06:35:49.034700Z

and gets the contents as an input stream

emccue 2020-10-01T06:36:18.035300Z

does anyone know why this is so slow and how can I improve it?

Karol Wójcik 2020-10-01T08:11:57.036900Z

What for you’re proxying the image? Wouldn’t be easier to just send url to resource?

Karol Wójcik 2020-10-01T08:13:26.037400Z

https://stackoverflow.com/a/33605888 that should be helpful.

emccue 2020-10-01T11:25:52.038Z

I had no clue about the presigned url thing

emccue 2020-10-01T12:07:08.038200Z

It seems like a nightmarish tunnel of CORS so far

Joe Lane 2020-10-01T15:13:39.039800Z

@emccue You could also serve the images through the cloudfront CDN Backed by S3. Can include auth and everything, then your webservers aren't burdened with all that io / memory usage.

Janne Sauvala 2020-10-01T15:34:07.045200Z

Sorry for hijacking the above discussion but it is close to a problem I have been thinking. How about the other way around when you want the user to be able to save images to S3 and store information about that image to your DB (user abc112 has uploaded image cat-foobar.jpg). One option is that the frontend client directly stores the image to S3 and then reports to backend API that image was stored with a name X. But these two operations are not atomic and if the image upload is successful and backend API call fails then I have an image in S3 that does not have DB record. Any thoughts how this could be solved?

isak 2020-10-01T15:49:03.045300Z

One way is to have them upload to an s3 bucket that gets autowiped after a day (or something) (There are lifecycle policies that enable this, IIRC). Then if you get the acknowledgement that they successfully uploaded, move that object to your real storage bucket.

abdullahibra 2020-10-01T15:50:51.045600Z

Hello everyone,

abdullahibra 2020-10-01T15:51:46.046500Z

i'm using vector based routes, how can i pass not common interceptors for get and post for the same route

abdullahibra 2020-10-01T15:52:43.047400Z

for example: ["/company" {:get company/get-all :post [:create-company company/create!]} ^:interceptors [auth]]

abdullahibra 2020-10-01T15:53:27.048200Z

now how can i add new interceptor for post for example: validate-new-company

abdullahibra 2020-10-01T15:53:28.048400Z

?

abdullahibra 2020-10-01T15:54:17.049200Z

i assume interceptors defined as metadata for get and post for company are common

abdullahibra 2020-10-01T15:54:37.049600Z

but i only want to apply validate-new-company for only post

emccue 2020-10-01T15:55:23.049700Z

I am gonna be doing this too

emccue 2020-10-01T15:59:42.050800Z

My current plan to handle this is to somehow have the user's upload be key'ed under a uuid

emccue 2020-10-01T15:59:49.051Z

and then who cares

✔️ 1
emccue 2020-10-01T16:00:16.051300Z

and I can run a background job to clean it up later, if my bill goes too high or something

emccue 2020-10-01T16:02:57.051900Z

(also maybe a good trigger point to have this not be empty)

emccue 2020-10-01T16:02:59.052100Z

http://pedestal.io/guides/uploading-files

emccue 2020-10-01T16:03:26.052700Z

(considering its the third result on google right after example repos)

Joe Lane 2020-10-01T16:04:16.052800Z

You can use an s3 lambda trigger to call your API / put a message onto SQS that adds that record to your database.

👍 1
Janne Sauvala 2020-10-01T16:08:50.054100Z

Good ideas, thanks!

dangercoder 2020-10-01T17:33:07.055800Z

I found something when using pedestal. The first request (when i boot up the web server) always takes a long time (1 seconds~) then it's 20-40ms 🙂 What could be the cause?

dangercoder 2020-10-01T17:34:29.056Z

This is on localhost without TLS.

emccue 2020-10-01T19:32:47.056300Z

What is the cost of this approach vs S3?

emccue 2020-10-01T19:33:02.056500Z

I've never used cloudfront CDN before

Joe Lane 2020-10-01T19:33:56.056700Z

How do you want to measure it?

Joe Lane 2020-10-01T19:34:12.056900Z

Time? Dollars? Complexity? Performance?

emccue 2020-10-01T20:56:24.057300Z

emccue 2020-10-01T20:56:34.057800Z

somewhat confused why json params would be a map of string->string

emccue 2020-10-01T20:56:53.058200Z

shouldn't it be an "Any" just like edn?

emccue 2020-10-01T20:57:10.058600Z

since [1, 2, 3] is valid json

emccue 2020-10-01T20:57:16.058900Z

and so is {"a": 10}

emccue 2020-10-01T21:02:02.059100Z

is this just a docs mistake?

souenzzo 2020-10-02T18:23:21.060400Z

For is. It shoud be any? JSON also allow values like 42 true false "s"