ChanServ changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
DTZUZU_ has joined #crystal-lang
DTZUZU has quit [Ping timeout: 268 seconds]
<FromGitter> <asterite> You have to keep the Query object somewhere (like a class var) otherwise the GC will collect it
<FromGitter> <mixflame> can anyone tell me what's wrong with this code? https://gist.github.com/mixflame/8be6f6ae13d5a5da2d3b8c88eac00ec6
<FromGitter> <mixflame> i tried to port generated net/http code to crystal
<FromGitter> <mixflame> {"data":{"error":"No image data was sent to the upload api","request":"\/3\/image","method":"POST"},"success":false,"status":400}
DTZUZU has joined #crystal-lang
<FromGitter> <Blacksmoke16> Would help if you provided the error or a hint of what's not working
<FromGitter> <mixflame> it seems like content-length is getting set to 0 even tho i have a body? could be a crystal bug or me doin something wrong. the form posts and then imgur returns that hash
<FromGitter> <Blacksmoke16> mm do you need to do `io.rewind` first?
<FromGitter> <hedgehog1029> there is definitely some bad code happening there
DTZUZU_ has quit [Ping timeout: 265 seconds]
<FromGitter> <naqvis> also do you really need to code those content-dispositions yourself?
<FromGitter> <mixflame> the field are part of the imgur api
<FromGitter> <naqvis> i would suggest to take a look at `HTTP::FormData#build` documentation
<FromGitter> <hedgehog1029> yeah the `FormData::Builder` will help out here
<FromGitter> <hedgehog1029> also just use `client.post`
<FromGitter> <mixflame> i'm using `FormData::Builder` in the code, just think i'm using it wrong
<FromGitter> <hedgehog1029> you will need to rewind the IO also
<FromGitter> <naqvis> > Another common case is sending formdata to a server using HTTP::Client. Here is an example showing how to upload a file to the server above in crystal. ⏎ https://crystal-lang.org/api/1.0.0/HTTP/FormData.html ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60a1c6a8e263442db830c7d1]
<FromGitter> <hedgehog1029> but you're doing weird bits like converting the IO to a string
<FromGitter> <hedgehog1029> yeah that example is good
<FromGitter> <mixflame> there's a bug in crystal or amber
<FromGitter> <mixflame> that code produces File path: {"data":{"error":"No image data was sent to the upload api","request":"\/3\/image","method":"POST"},"success":false,"status":400} too
<FromGitter> <Blacksmoke16> Did you rewind the Io?
deavmi has quit [Ping timeout: 260 seconds]
<FromGitter> <mixflame> i tried rewinding a few times and that did nothing
<FromGitter> <mixflame> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60a1d2e65ca66330b049185f]
<FromGitter> <mixflame> i think it's failing to send the content-length, there's a bug when specifying content-length, it doesn't permit the request to be sent
chachasmooth has quit [Ping timeout: 260 seconds]
chachasmooth has joined #crystal-lang
<FromGitter> <mixflame> i think there is definitely a bug in crystal, this 500's for no reason
<FromGitter> <mixflame> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60a1d678416d8734b94d99ee]
<FromGitter> <naqvis> did you tested this code on some local server?
<FromGitter> <naqvis> imgur requires OAUTH and i don't see that in your code
<FromGitter> <naqvis> that might be the reason you are receiving those 4XX error
<FromGitter> <naqvis> make sure you following the guidelines of imgur https://apidocs.imgur.com/
chachasmooth has quit [Ping timeout: 265 seconds]
chachasmooth has joined #crystal-lang
deavmi has joined #crystal-lang
<FromGitter> <mixflame> i solved it
<FromGitter> <mixflame> wasn't auth, you are allowed to use it anonymously with a client-ID, thanks tho Ali
<FromGitter> <mixflame> this is the working code if you're wondering
<FromGitter> <mixflame> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60a1f0f8c12aec4aa2ccf23b]
DTZUZU_ has joined #crystal-lang
<FromGitter> <naqvis> @mixflame 👍
<FromGitter> <naqvis> so it was missing `content_length` attribute which was causing the problem?
DTZUZU has quit [Ping timeout: 252 seconds]
early has quit [Quit: Leaving]
early has joined #crystal-lang
DTZUZU has joined #crystal-lang
DTZUZU_ has quit [Ping timeout: 240 seconds]
<FromGitter> <mixflame> yes missing content length for one and body and content length had to match
<FromGitter> <mixflame> and the file had to be named "image" and not "file"
<FromGitter> <naqvis> 👍
DTZUZU_ has joined #crystal-lang
DTZUZU has quit [Ping timeout: 240 seconds]
hendursaga has quit [Ping timeout: 240 seconds]
hendursaga has joined #crystal-lang
sz0 has joined #crystal-lang
deavmi has quit [Ping timeout: 260 seconds]
deavmi has joined #crystal-lang
<FromGitter> <Daniel-Worrall> `true ? a = 1 : a = nil` The compiler currently treats `a` as `Int32?`. Would it be easy for the compiler to not consider unreachable paths like this?
Stephanie is now known as Stephie
<FromGitter> <asterite> Yes, trivial if the condition is a true literal. Why do you need it, though?
deavmi has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
<FromGitter> <Daniel-Worrall> I don't, I just figure it might help in cases of bad code (less in the case of a literal, more in the case of a truthy variable
<repo> does the crystal mime multipart implementation support decoding quoted printable encoded text?
<repo> i'm writing a mua in crystal and i have to deal with such horrors
<FromGitter> <naqvis> repo i would say yes, it does
johnny101 has quit [Ping timeout: 240 seconds]
<repo> that's good news
<repo> naqvis: hm it looks like it just yields the body
<repo> without decoding it
<FromGitter> <naqvis> and that's how `HTTP.dequote_string` would work ⏎ https://play.crystal-lang.org/#/r/b5pu
<FromGitter> <naqvis> make sure you are using `HTTP::FormData.parse`
<FromGitter> <naqvis> error is clear enough :P
<FromGitter> <naqvis> so how are you getting that data?
<repo> naqvis: i'm just reading raw email files
<FromGitter> <naqvis> don't think stdlib has that available
<FromGitter> <naqvis> you will have to come up with implementation and better to make that as a shard for community to benefit
<FromGitter> <naqvis> you will need to implement RFC 2045 (https://datatracker.ietf.org/doc/html/rfc2045)
sagax has quit [Ping timeout: 246 seconds]
johnny101 has joined #crystal-lang
johnny101 has quit [Ping timeout: 265 seconds]
DTZUZU has joined #crystal-lang
DTZUZU_ has quit [Ping timeout: 240 seconds]
johnny101 has joined #crystal-lang
johnny101 has quit [Ping timeout: 240 seconds]
johnny101 has joined #crystal-lang
johnny101 has quit [Ping timeout: 250 seconds]
johnny101 has joined #crystal-lang
johnny101 has quit [Ping timeout: 252 seconds]
sagax has joined #crystal-lang
johnny101 has joined #crystal-lang