multipart_streaming_example

command
v1.9.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2025 License: MIT Imports: 9 Imported by: 0

README

Multipart Streaming Example

This example demonstrates streaming data between two servers using http-client.

Architecture

  • Server 1 (:8080): Generates a large file and returns it upon request to /file.
  • Server 2 (:8081): Accepts a multipart request on /upload and save file.
  • Client: Requests the file from Server 1, streams it directly into a multipart request to Server 2.

Running

Run the servers and client in separate terminals:

  1. Server 1:
cd server1
go run main.go
  1. Server 2:
cd server2
go run main.go
  1. Client (after starting the servers):
go run main.go
Alternative: Without Fluent API

For comparison, there's an alternative implementation in multipart_straming_without_fluent_api/main.go that achieves the same streaming behavior using only standard Go libraries (net/http, mime/multipart, io.Pipe) without the custom http-client library or fluent API.

To run the alternative client:

cd multipart_straming_without_fluent_api
go run main.go

This version demonstrates how to implement multipart streaming manually, providing the same memory-efficient results.

Result

  • Server 1 generates file with numbered lines.
  • Client streams the file from Server 1 to Server 2 without intermediate storage.
  • Server 2 saves the file in its directory.
  • Client outputs upload confirmation.
  • Streaming progress in the logs

Notes

  • Data is transferred in a streaming manner, without loading into the client's memory.
  • Uses io.Reader for streaming.
  • In a real application, replace file generation with reading from a source.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL