Fork me on GitHub
#yada
<
2017-01-11
>
malcolmsparks07:01:27

@lmergen you can avoid using the :parameters declaration for now and just pull out the parameters in (:parameters ctx) and do clojure.spec validation on those manually . clojure.spec support will come in a future release, but probably not until Clojure 1.9 is out of alpha

lmergen08:01:47

I wonder whether it makes sense to spec the handler function's ctx

lmergen08:01:23

to ensure that those parameters are always there in the form I expect it to be

malcolmsparks08:01:47

Doesn't that end up calling the function itself? Unless your response function is pure, that might not be good

lmergen08:01:42

oh yeah you're right of course

danielgrosse09:01:22

Hello. Do you now a simple upload example with yada, where I can learn from?

malcolmsparks09:01:45

Look at the tests, especially multipart.

danielgrosse09:01:00

I use the edge repo from juxt. When I run it and want to println something in the response function. Nothing is logged in the repl

malcolmsparks11:01:03

Use clojure.tools.logging because println requires out thread binding to be set to the REPL.

danielgrosse11:01:29

Arrg. I had to restart boot dev to get the changes of the route working.

malcolmsparks11:01:54

A (reset) should be all that is needed.

malcolmsparks11:01:05

When you println on a web request thread, the out dynamic var is not set, that's why prontln doesn't work

danielgrosse11:01:09

When I upload a file. I get the multiparts. How do I send the data further to another function?

malcolmsparks11:01:09

You create your own PartConsumer

malcolmsparks11:01:26

Hang on that's wrong

malcolmsparks11:01:59

can you explain what you're trying to do

malcolmsparks11:01:27

do you mean you want to process the part's stream yourself (to avoid memory exhaustion with loading it into memory)?

malcolmsparks11:01:39

or do you just want to take a part and process it?

malcolmsparks11:01:56

the parts are put into the context by the multipart processor, you can fish them out from there in your response function

malcolmsparks11:01:16

Have a look at bundles/full/test/yada/multipart_test.clj for examples

danielgrosse11:01:29

I write a little prototype to test how I can upload several image files, which are then send to an s3 storage and also be processed by another function.

malcolmsparks11:01:26

If you want to do that, it's possible to write your own PartConsumer which lets you plug-in to the multipart part stream processing and stream to S3, although I'm not sure how this is actually implemented by those who have

malcolmsparks11:01:06

if they are image files then you're probably fine to just keep in memory, and in your response function you can fish them out of the context as byte arrays and then copy to S3

lmergen12:01:25

what would be the best way for yada to output the exceptions that occur in the response function ?

lmergen12:01:39

it seems that the default behaviour is to return an empty body

lmergen12:01:55

or is that because of my :produces constraints, which only allow json and edn ?

malcolmsparks12:01:33

if you throw exceptions in the response function, yada should render them properly for you (renegotiating the content type along the way) @lmergen - which version of yada are you talking about?

danielgrosse13:01:29

In your upload example, which you deleted at tag 1.20, you wrote a body-stream in the consumer function to a temporary file. I used it, but when I upload a png file, the tmp file isn't viewable anymore.

danielgrosse13:01:15

Is this only usable for octet streams?

malcolmsparks13:01:03

when you say it's not viewable anymore, are you saying the file has corrupted? What client are you using to upload?

danielgrosse13:01:15

This png file, becomes this tmp file

danielgrosse13:01:25

I use chrome to upload the file

malcolmsparks13:01:39

is the file the same except the suffix?

malcolmsparks13:01:46

is there are file size difference?

danielgrosse13:01:50

No. Its different

malcolmsparks13:01:57

is the tmp file smaller?

danielgrosse13:01:03

67byte original

danielgrosse13:01:06

As I see, the request header has a content-length of 259 bytes.

danielgrosse13:01:30

So maybe its the wrong way I try to solve this.

malcolmsparks13:01:16

yes, I see the problem

malcolmsparks13:01:38

you are providing your own consumer here -the original example (that I deleted!) was for saving an entire stream

malcolmsparks13:01:54

in your case you want yada to process the multipart/form-data body

malcolmsparks13:01:07

so don't override the consumer here with :consumer

malcolmsparks13:01:15

in this case, use the :response function - it the context you will have byte arrays under :body

malcolmsparks13:01:54

print out body and you should see a map of multipart 'names' and the parts

malcolmsparks13:01:00

the names are extracted from the Content-Disposition header - if you want to get access to the whole part (to give you full access to the headers - e.g. you'll need the Content-Type of the image to know if it's png or jpeg), then you can use :yada.multipart/parts

malcolmsparks13:01:20

this is a bit of 'hidden knowledge' I'm afraid, but it's a fairly recent 'feature'

danielgrosse13:01:19

Is there a middleware in yada, which converts the header into a map? The current header of the multipart is a string

malcolmsparks13:01:55

there's some code in Ring that can do it

malcolmsparks13:01:12

sorry, I'm a bit busy right now

danielgrosse13:01:30

No Problem. Its not that urgent

danielgrosse14:01:11

How is the encoding handled in yada? I can set :charset in :produces. But when I try it in :consumes it doesn't make a difference. I have a filename which has umlauts in it. They are not converted to the right charcode in the response map.

lmergen14:01:36

@malcolmsparks i'm running version 1.2.0

lmergen14:01:58

but that's strange, i'm seeing empty body responses

lmergen14:01:02

what would be the best way to debug this ?

lmergen14:01:00

does it have anything to do with running a dev or prod profile ?

dominicm14:01:34

@lmergen I was seeing the empty body responses until I upgraded to 1.2.0

vijayakkineni19:01:59

Hi All, I am trying to use log4j2 MDC ThreadContext and ThreadContext information set in an interceptor is not getting forwarded to the other interceptors down the chain as yada interceptors are getting executed on separate threads in manifold thread pool. How do we handle this?

lmergen22:01:25

@vijayakkineni i think that those things like ThreadContext are inherently incompatible with an async-like execution model which yada uses

lmergen22:01:00

i think that the best solution will involve passing around the context explicitly

vijayakkineni22:01:13

@lmergen thank you, I am modifying the context and passing it around.