technoweenie/multipartstreamer

语言: Go

git: https://github.com/technoweenie/multipartstreamer

README.md (中文)

multipartstreamer

包multipartstreamer可帮助您以MIME多部分格式编码大型文件 无需将整个内容读入内存。它使用io.MultiReader来 将内部multipart.Reader与文件句柄组合在一起。

package main

import (
  "github.com/technoweenie/multipartstreamer.go"
  "net/http"
)

func main() {
  ms := multipartstreamer.New()

  ms.WriteFields(map[string]string{
    "key":          "some-key",
    "AWSAccessKeyId":   "ABCDEF",
    "acl":          "some-acl",
  })

  // Add any io.Reader to the multipart.Reader.
  ms.WriteReader("file", "filename", some_ioReader, size)

  // Shortcut for adding local file.
  ms.WriteFile("file", "path/to/file")

  req, _ := http.NewRequest("POST", "someurl", nil)
  ms.SetupRequest(req)

  res, _ := http.DefaultClient.Do(req)
}

一个限制:您只能编写单个文件。

ALL

  • 多个文件?

积分

詹姆斯深受启发

HTTPS://groups.Google.com/forum/?from groups=#!topic/go浪-nuts/z结果5来4NK CQ0

本文使用googletrans自动翻译,仅供参考, 原文来自github.com

en_README.md

multipartstreamer

Package multipartstreamer helps you encode large files in MIME multipart format
without reading the entire content into memory. It uses io.MultiReader to
combine an inner multipart.Reader with a file handle.

package main

import (
  "github.com/technoweenie/multipartstreamer.go"
  "net/http"
)

func main() {
  ms := multipartstreamer.New()

  ms.WriteFields(map[string]string{
    "key":          "some-key",
    "AWSAccessKeyId":   "ABCDEF",
    "acl":          "some-acl",
  })

  // Add any io.Reader to the multipart.Reader.
  ms.WriteReader("file", "filename", some_ioReader, size)

  // Shortcut for adding local file.
  ms.WriteFile("file", "path/to/file")

  req, _ := http.NewRequest("POST", "someurl", nil)
  ms.SetupRequest(req)

  res, _ := http.DefaultClient.Do(req)
}

One limitation: You can only write a single file.

TODO

  • Multiple files?

Credits

Heavily inspired by James

https://groups.google.com/forum/?fromgroups=#!topic/golang-nuts/Zjg5l4nKcQ0