Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG? - Multipart upload removes content-length #42

Open
eric-s-s opened this issue Nov 14, 2019 · 1 comment
Open

BUG? - Multipart upload removes content-length #42

eric-s-s opened this issue Nov 14, 2019 · 1 comment

Comments

@eric-s-s
Copy link

eric-s-s commented Nov 14, 2019

According to your code, you need to calculate content-length for multi-part uploads. After doing that, you specifically upload multipart as chunked data with no content-length. This has led to issues for me exactly because of the reason stated in line 155.

when i try to POST, content-length is removed from the headers

If i make a post with:

    val session: Session = requests.Session(
      headers = Map(
        "user-agent" -> userAgentHeader,
        "authorization" -> authHeader,
        "accept" -> "*/*",
        "content-type" -> "application/json; charset=utf-8"
      )
    )
val file = new File("path-to-file")
val multiPart = MultiPart(MultiItem("file", file, file.getName))
val headers = Map(
    "thing" -> "thang",
     "Content-Length" -> multiPart.totalBytesToSend.toString,
      "content-type" -> s"multipart/form-data; boundary=${multiPart.boundary}"
)
session.post("a url", data = multiPart, headers = headers)

When I POST to myself and look at the headers, the content-length is gone, because it is controlled at the Java level here

My current workaround is this

case class SizedMultiPart(items: requests.MultiItem*)
    extends requests.RequestBlob.MultipartFormRequestBlob(items)
    with requests.RequestBlob.SizedBlob {

  override def length: Long = totalBytesToSend

  override def inMemory: Boolean = false
  override def headers: Seq[(String, String)] = Seq(
    "Content-Type" -> s"multipart/form-data; boundary=$boundary",
    "Content-Length" -> totalBytesToSend.toString
  )
}

After going through all the trouble of calculating size for MultiPartFormRequestBlob, is there a reason why that is then discarded by making MultiPart not a SizedRequestBlob?

@eric-s-s eric-s-s changed the title Multipart upload and content-length BUG? - Multipart upload removes content-length Nov 27, 2019
@DavidPerezIngeniero
Copy link

It seems multipart doesn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants