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 #91

Open
mr-cloud opened this issue Sep 12, 2022 · 1 comment
Open

BUG? - Multipart upload removes content-length #91

mr-cloud opened this issue Sep 12, 2022 · 1 comment

Comments

@mr-cloud
Copy link
Owner

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?
ID: 42
Original Author: eric-s-s
link: Original Link

@mr-cloud
Copy link
Owner Author

It seems multipart doesn't work.
Original Author:DavidPerezIngeniero

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

1 participant