https://github.com/lyrictian/fuh
A file upload library for Go.
https://github.com/lyrictian/fuh
go-file-upload go-upload upload-handler
Last synced: about 2 months ago
JSON representation
A file upload library for Go.
- Host: GitHub
- URL: https://github.com/lyrictian/fuh
- Owner: LyricTian
- License: mit
- Created: 2017-02-04T14:35:07.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-12-22T11:57:19.000Z (over 5 years ago)
- Last Synced: 2025-03-28T14:21:14.679Z (2 months ago)
- Topics: go-file-upload, go-upload, upload-handler
- Language: Go
- Homepage:
- Size: 22.5 KB
- Stars: 10
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Golang File Upload Handler
[![Build][Build-Status-Image]][Build-Status-Url] [![Codecov][codecov-image]][codecov-url] [![ReportCard][reportcard-image]][reportcard-url] [![GoDoc][godoc-image]][godoc-url] [![License][license-image]][license-url]
## Quick Start
### Download and install
```bash
go get -v github.com/LyricTian/fuh
```### Create file `server.go`
```go
package mainimport (
"context"
"encoding/json"
"net/http"
"path/filepath""github.com/LyricTian/fuh"
)func main() {
upl := fuh.NewUploader(&fuh.Config{
BasePath: "attach",
SizeLimit: 1 << 20,
}, fuh.NewFileStore())http.HandleFunc("/fileupload", func(w http.ResponseWriter, r *http.Request) {
ctx := fuh.NewFileNameContext(context.Background(), func(ci fuh.ContextInfo) string {
return filepath.Join(ci.BasePath(), ci.FileName())
})finfos, err := upl.Upload(ctx, r, "file")
if err != nil {
w.WriteHeader(500)
return
}
json.NewEncoder(w).Encode(finfos)
})http.ListenAndServe(":8080", nil)
}
```### Build and run
```bash
$ go build server.go
$ ./server
```## Features
- Custom file name
- Custom file size limit
- Supports storage extensions
- Context support## MIT License
Copyright (c) 2017 Lyric
[Build-Status-Url]: https://travis-ci.org/LyricTian/fuh
[Build-Status-Image]: https://travis-ci.org/LyricTian/fuh.svg?branch=master
[codecov-url]: https://codecov.io/gh/LyricTian/fuh
[codecov-image]: https://codecov.io/gh/LyricTian/fuh/branch/master/graph/badge.svg
[reportcard-url]: https://goreportcard.com/report/github.com/LyricTian/fuh
[reportcard-image]: https://goreportcard.com/badge/github.com/LyricTian/fuh
[godoc-url]: https://godoc.org/github.com/LyricTian/fuh
[godoc-image]: https://godoc.org/github.com/LyricTian/fuh?status.svg
[license-url]: http://opensource.org/licenses/MIT
[license-image]: https://img.shields.io/npm/l/express.svg