multipartstream

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: MIT Imports: 8 Imported by: 0

README

MultipartStream

Multipartstream offers multipart/form-data body requests as stream object, avoiding overheads on upload processes by larger files.

Its currently under development, so there's no garrantees of stability or backwards compatibility.

Installation

go get github.com/isaquecsilva/multipartstream

Example Usage:

package main

import (
    "os"
    "strings"
    "net/http"

    ms "github.com/isaquecsilva/multipartstream"
)

func main() {
    // new multipartStream instance
    form := ms.NewMultipartStream()

    // adding a new form field called 'sender'
    form.FormField("sender", strings.NewReader("Herold"))
    
    // loading file to upload
    example, err := os.Open("example.txt")
    if err != nil {
        panic(err)
    }
    defer example.Close()

    // adding our example.txt file, and checking for mimetypes errors.
    if err = form.FormFile("file", "example.txt", example); err != nil {
    	panic(err)
    }

    // adding trailing boundary signaling multipart/form-data body end.
    form.Done()

    // our http request    
    req, _ := http.NewRequest(http.MethodPost, endpoint, form)

    // sending request
    http.DefaultClient.Do(req)
}

Inspiration

It was inspired on famous Go package technoweenie/multipartstreamer

License

  • Terms of use for Multipartstream resides under MIT license.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MultipartStream added in v0.1.1

type MultipartStream struct {
	// contains filtered or unexported fields
}

func NewMultipartStream

func NewMultipartStream() *MultipartStream

NewMultipartStream creates a new instance os *MultipartStream object.

func (*MultipartStream) Boundary added in v0.1.1

func (ms *MultipartStream) Boundary() string

Boundary returns MultipartStream multipart/form-data boundary value.

func (*MultipartStream) ContentType added in v0.1.1

func (ms *MultipartStream) ContentType() string

ContentType returns an HTTP Content-Type header value according to multipart/form-data with the generated boundary by NewMultipartStream.

func (*MultipartStream) Done added in v0.1.1

func (ms *MultipartStream) Done()

Done inserts trailling boundary signaling the end of the multipart/form-data body request.

func (*MultipartStream) FormField added in v0.1.1

func (ms *MultipartStream) FormField(fieldName string, r io.Reader)

FormField adds a new form field to current multipart/form-data body. It panics if `r` is nil.

func (*MultipartStream) FormFile added in v0.1.1

func (ms *MultipartStream) FormFile(fieldName, filename string, r io.Reader) error

FormFile adds a new form file field in current multipart/form-data body. It panics if `r` is nil. The returned error, if there is one, will be related with mime type parsing failures.

func (*MultipartStream) Read added in v0.1.1

func (ms *MultipartStream) Read(buf []byte) (int, error)

Read implements io.Reader interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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