Spring's RestClient and RestTemplate fail to successfully upload video files to Streamable's API, even when configured with multipart/form-data and proper authentication.

Issue Summary: Streamable's /upload endpoint only accepts raw HTTP multipart form data as per their internal implementation.

Using RestClient (Spring 3.x) or RestTemplate to upload a FileSystemResource or ByteArrayResource always results in:

  • 400 Bad Request: [no body]

  • I/O error on POST request

  • Connection reset by peer

These errors are reproducible consistently and confirmed by direct curl or HttpURLConnection upload (which succeed).

Error Cases: Direct binary upload (application/octet-stream) via RestClient.post() returns:

500 INTERNAL SERVER ERROR

Oops!

We're having some issues...

Multipart upload using: MultipartBodyBuilder builder = new MultipartBodyBuilder(); builder.part("file", new FileSystemResource(file)); I/O error: Remote host terminated the handshake Workaround: The only reliable upload method is to manually build the raw multipart form body and stream it using HttpURLConnection or low-level HttpClient, **Comment From: bclozel** Thanks for raising this, but it sounds like you will need to adapt the type of HTTP call you should make here, because of the remote /upload endpoint. At this stage, it's not clear what kind of HTTP request is expected from that endpoint and why support is lacking in Spring for that. Maybe if you could provide the command+output of a `curl -v` successful request, we can better understand the problem? **Comment From: spring-projects-issues** If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed. **Comment From: akshatvermavi** Hi team, Thanks for your earlier input. After extensive debugging and analysis, I was able to successfully resolve the issue with Streamable's /upload endpoint. As suspected, Spring's RestClient and RestTemplate fail to serialize multipart/form-data in the exact format Streamable expects, leading to either 400 Bad Request or handshake termination errors. **Resolution Summary:** I implemented a hybrid approach using low-level byte array construction of the multipart body, ensuring full control over boundaries and headers. This is streamed via a ByteArrayResource and posted using RestClient. The critical fix was avoiding Spring’s default multipart encoder and instead manually crafting the multipart/form-data body with the appropriate Content-Disposition, Content-Type, and boundary headers. I also added fallback support and retry logic, switching to multipart if direct binary upload fails, with proper polling of status and error handling. The upload is now stable, handles retries, supports large files (within Streamable’s free-tier limit), and integrates seamlessly into the service layer. Thanks again for the quick triage. Closing this from my side as resolved. Akshat Verma **Comment From: bclozel** Thanks for letting us know. I don't think you should have to bypass Spring's multipart support and I wouldn't advise this for most applications. We can't really provide more advice here since you didn't share the requested information. In all cases, I'm glad this is working out for you.