Fork me on GitHub
#ring-swagger
<
2016-10-11
>
singen12:10:43

@ikitommi et al, I’m having a hard time figuring out what format file uploads expect in compojure-api. The file upload example in https://github.com/metosin/compojure-api/wiki/Swagger-aware-File-uploads results in a swagger api-doc that doesn’t work.

singen12:10:27

Almost anything I can think up to try in curl results in one error or another

singen12:10:34

It’s almost like it thinks the file itself should be JSON

ikitommi12:10:38

lein new compojure-api singen
cd singen
[edit]
lein ring server

singen12:10:52

I copied the /upload part 1 for 1 into my own api

singen12:10:10

And then I tried to upload a file from swagger

singen12:10:53

This was the result

singen12:10:38

Whoops… never mind 😄 must have made some kind of copy/paste error

singen12:10:45

It works now'

singen12:10:04

Ok, so in my confusion I though I had tried TempFileUpload, but I was actually trying out ByteArrayUpload

singen12:10:17

Which does result in an error

ikitommi13:10:04

ok. good to hear it works

singen13:10:02

Yeah, now my question is reformed as: How do you upload as ByteArrayUpload?

singen13:10:22

@juhoteperi I was trying to ask for a client example, but failing obviously.

juhoteperi13:10:52

Whether compojure uses tempfile or bytearray doesn't depend on client at all

singen13:10:20

It expects a different type of data input

singen13:10:44

Ummm… yes, I can prove it

singen13:10:31

If I change the type of the data store, I can no longer upload a file with curl

juhoteperi13:10:31

"bytes=" and "file=" are the name of multipart param

juhoteperi13:10:42

:multipart-params [file :- upload/TempFileUpload] <- file here

juhoteperi13:10:01

that could also be [foo :- upload/TempFileUpload], name doesn't depend on type

juhoteperi13:10:11

and you would use that as foo=@file from curl

singen13:10:21

No, it doesn’t work that way

juhoteperi13:10:24

name is not related to if you are using byte array or temp file

singen13:10:57

The second curl works if the datastore is tempfile

singen13:10:03

ByteArrayUpload seems to expect that the is a field named bytes somewhere in the upload, but there isn't

juhoteperi13:10:43

That field is created by Ring middleware, when using byte-array store

juhoteperi13:10:53

But one sec, testing

singen14:10:03

Of course, curl is a bit limited as a client, but I was just trying to find out what is expected from the client application

juhoteperi14:10:32

~/Source/metosin/compojure-api master*
❯ curl -X POST -F "[email protected]"  localhost:3000/upload/file
{"filename":"project.clj","content-type":"application/octet-stream","size":3291}
~/Source/metosin/compojure-api master*
❯ curl -X POST -F "[email protected]"  localhost:3000/upload/byte-array
{"filename":"project.clj","content-type":"application/octet-stream"}

singen14:10:58

Aha! I need additional parameters to the wrap!

singen14:10:08

Thank you!

singen14:10:53

You might actually want to leave that example in there

singen14:10:11

@juhoteperi I just noticed that this is exactly what you first said. I must hang my head in shame and dribble ashes upon my person.