{"id":22423432,"url":"https://github.com/prantlf/go-multipart-composer","last_synced_at":"2025-03-27T05:41:02.284Z","repository":{"id":144226673,"uuid":"312215712","full_name":"prantlf/go-multipart-composer","owner":"prantlf","description":"Prepares bodies of HTTP requests with MIME multipart messages without reading entire file contents to memory.","archived":false,"fork":false,"pushed_at":"2022-01-29T15:52:32.000Z","size":24,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-01T10:43:05.364Z","etag":null,"topics":["form-data","go","go-module","go-package","multipart","multipart-formdata","streaming"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/prantlf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-12T08:38:27.000Z","updated_at":"2023-03-19T18:47:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"6840dfc9-0df4-4ca8-9bd6-10af237c1de3","html_url":"https://github.com/prantlf/go-multipart-composer","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Fgo-multipart-composer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Fgo-multipart-composer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Fgo-multipart-composer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Fgo-multipart-composer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prantlf","download_url":"https://codeload.github.com/prantlf/go-multipart-composer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245791899,"owners_count":20672668,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["form-data","go","go-module","go-package","multipart","multipart-formdata","streaming"],"created_at":"2024-12-05T18:11:18.547Z","updated_at":"2025-03-27T05:41:02.262Z","avatar_url":"https://github.com/prantlf.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-multipart-composer\n\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/prantlf/go-multipart-composer)](https://pkg.go.dev/github.com/prantlf/go-multipart-composer)\n[![Test Status](https://github.com/prantlf/go-multipart-composer/workflows/Test/badge.svg)](https://github.com/prantlf/go-multipart-composer/actions)\n[![codecov](https://codecov.io/gh/prantlf/go-multipart-composer/branch/master/graph/badge.svg?token=XS0COPSRR7)](https://codecov.io/gh/prantlf/go-multipart-composer)\n\nPrepares bodies of HTTP requests with MIME multipart messages according to [RFC7578] without reading entire file contents to memory. Instead of writing files to a [multipart writer] right away, it collects [readers] for each part of the form and lets them stream to the network once the request has been sent. Avoids buffering of the request body simpler than with [goroutines] and [pipes]. See the [documentation] for more information.\n\n## Installation\n\nAdd this package to `go.mod` and `go.sub` in your Go project:\n\n    go get github.com/prantlf/go-multipart-composer\n\n## Usage\n\nUpload a file with comment:\n\n```go\nimport (\n  \"net/http\"\n  composer \"github.com/prantlf/go-multipart-composer\"\n)\n// compose a multipart form-data content\ncomp := composer.NewComposer()\ncomp.AddField(\"comment\", \"a comment\")\nerr := comp.AddFile(\"file\", \"test.txt\")\n// post a request with the generated content type and body\nresp, err := http.DefaultClient.Post(\"http://host.com/upload\",\n  comp.FormDataContentType(), comp.DetachReader())\n```\n\nIf the server does not support chunked encoding and requires `Content-=Length` in the header:\n\n```go\ncomp := composer.NewComposer()\ncomp.AddField(\"comment\", \"a comment\")\nerr := comp.AddFile(\"file\", \"test.txt\")\nreqBody, contentLength, err := comp.DetachReaderWithSize()\nif err != nil {\n  comp.Close() // DetachReaderWithSize does not close the composer on failure\n  log.Fatal(err)\n}\n// post a request with the generated body, content type and content length\nreq, err := http.NewRequest(\"POST\", \"http://host.com/upload\", reqBody)\nreq.Header.Add(\"Content-Type\", comp.FormDataContentType())\nreq.ContentLength = contentLength\nresp, err := http.DefaultClient.Do(request)\n```\n\nSee the [documentation] for the full interface.\n\n[documentation]: https://pkg.go.dev/github.com/prantlf/go-multipart-composer#section-documentation\n[readers]: https://golang.org/pkg/io/#Reader\n[multipart writer]: https://golang.org/pkg/mime/multipart/#Writer\n[goroutines]: https://tour.golang.org/concurrency/1\n[pipes]: https://golang.org/pkg/io/#Pipe\n[RFC7578]: https://tools.ietf.org/html/rfc7578\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprantlf%2Fgo-multipart-composer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprantlf%2Fgo-multipart-composer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprantlf%2Fgo-multipart-composer/lists"}