outr / mailgun4s

Mailgun API implementation in Scala

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error Content length is too long on attached files

jeanmile opened this issue · comments

Hi,

I have this error with a large attached file. With a little file it's working.
Any idea how to solve this problem ?

play.api.Application$$anon$1: Execution exception[[ContentTooLongException: Content length is too long: 364727]]
	at play.api.Application$class.handleError(Application.scala:296) ~[play_2.11-2.3.9.jar:2.3.9]
	at play.api.DefaultApplication.handleError(Application.scala:402) [play_2.11-2.3.9.jar:2.3.9]
	at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3$$anonfun$applyOrElse$4.apply(PlayDefaultUpstreamHandler.scala:320) [play_2.11-2.3.9.jar:2.3.9]
	at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3$$anonfun$applyOrElse$4.apply(PlayDefaultUpstreamHandler.scala:320) [play_2.11-2.3.9.jar:2.3.9]
	at scala.Option.map(Option.scala:146) [scala-library-2.11.11.jar:na]
Caused by: org.apache.http.ContentTooLongException: Content length is too long: 364727
	at org.apache.http.entity.mime.MultipartFormEntity.getContent(MultipartFormEntity.java:103) ~[httpmime-4.5.3.jar:4.5.3]
	at org.apache.http.nio.entity.EntityAsyncContentProducer.produceContent(EntityAsyncContentProducer.java:65) ~[httpcore-nio-4.4.6.jar:4.4.6]
	at org.apache.http.nio.protocol.BasicAsyncRequestProducer.produceContent(BasicAsyncRequestProducer.java:125) ~[httpcore-nio-4.4.6.jar:4.4.6]
	at org.apache.http.impl.nio.client.MainClientExec.produceContent(MainClientExec.java:262) ~[httpasyncclient-4.1.3.jar:4.1.3]
	at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.produceContent(DefaultClientExchangeHandlerImpl.java:140) ~[httpasyncclient-4.1.3.jar:4.1.3]

That's insane! It would seem MultipartFormEntity has a hard limitation of 25kb file size. I've been really considering switching to Akka-Http or Http4s in the near future for youi-client. Looks like it might be time to do that. Of course, that doesn't help you at this moment.

Actually, there might be a work-around if I extend MultipartFormEntity. The other problem is that it loads the whole thing into memory (a ByteArrayOutputStream). If you are fine with the entire form loading into memory, I should be able to write a work-around that bypasses that exception being thrown?

Released 1.0.9 which should solve this by bypassing the limitation. Warning though that this will still hold the entire multipart content in memory while sending. I haven't had much time to test this, so please let me know if you have any further problems with it.