a tool for handling file uploads simple

Overview

baraka

Go Report Card codecov Build Status go.dev reference

a tool for handling file uploads for http servers

makes it easier to make operations with files from the http request.

Contents

Install

go get github.com/xis/baraka/v2

Simple Usage

func main() {
	// create a parser
	parser := baraka.NewParser(baraka.ParserOptions{
		MaxFileSize:   5 << 20,
		MaxFileCount:  5,
		MaxParseCount: 5,
	})

	store := baraka.NewFileSystemStore("./files")

	router := gin.Default()
	router.POST("/upload", func(c *gin.Context) {
		// parsing
		request, err := parser.Parse(c.Request)
		if err != nil {
			fmt.Println(err)
		}

		// get the form
		images, err := request.GetForm("images")
		if err != nil {
			fmt.Println(err)
		}

		// saving
		for key, image := range images {
			err = store.Save("images", "image_"+strconv.Itoa(key), image)
			if err != nil {
				fmt.Println(err)
			}
		}
	})
	router.Run()
}

you can use baraka with the other http server libraries, just pass the http.Request to the parser.Parse function.

Filtering Parts

You can filter parts by their properties, like part's content type. Parser can inspect the part's bytes and detect the type of the part with the Inspector.

// create a parser
parser := baraka.NewParser(baraka.ParserOptions{
	MaxFileSize:   5 << 20,
	MaxFileCount:  5,
	MaxParseCount: 5,
})

// give parser an inspector
parser.SetInspector(baraka.NewDefaultInspector(512))
// give parser a filter
parser.SetFilter(baraka.NewExtensionFilter(".jpg"))

Now parser will inspect the each part and it will just return the jpeg ones from the Parse function. You can make your own Inspector and Filter.

Contribute

pull requests are welcome. please open an issue first to discuss what you would like to change.

please make sure to update tests as appropriate.

License

MIT

You might also like...
Abstract File Storage

afs - abstract file storage Please refer to CHANGELOG.md if you encounter breaking changes. Motivation Introduction Usage Matchers Content modifiers S

Bigfile -- a file transfer system that supports http, rpc and ftp protocol   https://bigfile.site
Bigfile -- a file transfer system that supports http, rpc and ftp protocol https://bigfile.site

Bigfile ———— a file transfer system that supports http, rpc and ftp protocol 简体中文 ∙ English Bigfile is a file transfer system, supports http, ftp and

Go file operations library chasing GNU APIs.
Go file operations library chasing GNU APIs.

flop flop aims to make copying files easier in Go, and is modeled after GNU cp. Most administrators and engineers interact with GNU utilities every da

Read csv file from go using tags

go-csv-tag Read csv file from Go using tags The project is in maintenance mode. It is kept compatible with changes in the Go ecosystem but no new feat

File system event notification library on steroids.

notify Filesystem event notification library on steroids. (under active development) Documentation godoc.org/github.com/rjeczalik/notify Installation

Pluggable, extensible virtual file system for Go

vfs Package vfs provides a pluggable, extensible, and opinionated set of file system functionality for Go across a number of file system types such as

An epoll(7)-based file-descriptor multiplexer.

poller Package poller is a file-descriptor multiplexer. Download: go get github.com/npat-efault/poller Package poller is a file-descriptor multiplexer

QueryCSV enables you to load CSV files and manipulate them using SQL queries then after you finish you can export the new values to a CSV file
QueryCSV enables you to load CSV files and manipulate them using SQL queries then after you finish you can export the new values to a CSV file

QueryCSV enable you to load CSV files and manipulate them using SQL queries then after you finish you can export the new values to CSV file

Goful is a CUI file manager written in Go.
Goful is a CUI file manager written in Go.

Goful Goful is a CUI file manager written in Go. Works on cross-platform such as gnome-terminal and cmd.exe. Displays multiple windows and workspaces.

Comments
  • file slice  blob upload

    file slice blob upload

     while(start < totalSize){
    
            fd = new FormData();
    
            xhr = new XMLHttpRequest();
    
            xhr.open('POST',util.config.serviceUrl+'/test',false);
    
            blob = file.slice(start,end);
    
            fd.append('data',blob);
    
            xhr.send(fd);
    
            start = end;
    
            end = start + LENGTH;
    
        }
    

    When the blob was uploaded by the front-end slice, the program did not run properly

    [GIN] 2022/11/22 - 00:16:12 | 200 | 16.1792ms | 127.0.0.1 | POST "/test" form not found [GIN] 2022/11/22 - 00:16:12 | 200 | 17.023ms | 127.0.0.1 | POST "/test" form not found [GIN] 2022/11/22 - 00:16:12 | 200 | 15.1288ms | 127.0.0.1 | POST "/test" form not found [GIN] 2022/11/22 - 00:16:12 | 200 | 13.3188ms | 127.0.0.1 | POST "/test"

    opened by nimei66 0
  • Implementation of the S3 Store

    Implementation of the S3 Store

    We can create a S3Store (or another name) like FileSystemStore in the saver.go file.

    like,

    package baraka
    
    type S3Store struct {
        // specific settings
    }
    
    func NewS3Store(/* specific settings */) S3Store {
        return S3Store{
            // specific settings
        }
    }
    
    func (s S3Store) Save(path string, filename string, part *Part) error {
        // specific things to upload part's bytes to the s3
    }
    

    so, we can easily upload the files to the s3 with this implementation.

    enhancement help wanted good first issue 
    opened by xis 0
Releases(v2.0.3)
  • v2.0.2(Feb 4, 2021)

    you can get parts with their form names now added Inspector added Filter removed filter function removed processor removed informer request's parts field is a map now removed Parser interface

    Source code(tar.gz)
    Source code(zip)
  • v2.0.1(Dec 4, 2020)

  • v1.2.0(Dec 4, 2020)

    code is now more meaningful added available slices mechanism to use remaining []byte from the filtered parts added MaxParseCount variable to limit parse loop filter function now gets a []byte as a parameter Storage removed Marshaler removed removed Header related things from parser.Parse function, added Part struct to access data easily added NewParser function, Options renamed to ParserOptions, Parse method removed from Options, Options struct not implements Parser anymore, parser implements Parser interface now, parser can be created with NewParser function, now using Part struct instead of Header, not using Parts struct anymore, now using Request struct.

    Source code(tar.gz)
    Source code(zip)
  • v1.1.1(Aug 13, 2020)

  • v1.1.0(Aug 11, 2020)

    removed WithMultipartReader, WithParseMultipartForm options. library just uses multipart.Reader() now. added ParseButMax function, so you can set a maxFileSize and maxFileCount limit to parser. you can give prefixes when storing the file now.

    process.Store("user_image_")
    // it will be like this in filesystem
    // user_image_1.jpg
    // user_image_2.png
    // user-image_3.whatever
    

    process.Filenames() for getting names of files process.ContentTypes() for getting content types of files process.Length() for getting total count of files

    // prints filenames
    fmt.Println(process.Filenames())
    // prints total files count
    fmt.Println(process.Length())
    // prints content types of files
    fmt.Println(process.ContentTypes())
    

    new struct Options for all parsing purposes. new struct Parts for all file operations.

    Source code(tar.gz)
    Source code(zip)
  • v1.0.1(Jul 18, 2020)

Owner
Enes Furkan Olcay
at mühendisi
Enes Furkan Olcay
go-fastdfs 是一个简单的分布式文件系统(私有云存储),具有无中心、高性能,高可靠,免维护等优点,支持断点续传,分块上传,小文件合并,自动同步,自动修复。Go-fastdfs is a simple distributed file system (private cloud storage), with no center, high performance, high reliability, maintenance free and other advantages, support breakpoint continuation, block upload, small file merge, automatic synchronization, automatic repair.(similar fastdfs).

中文 English 愿景:为用户提供最简单、可靠、高效的分布式文件系统。 go-fastdfs是一个基于http协议的分布式文件系统,它基于大道至简的设计理念,一切从简设计,使得它的运维及扩展变得更加简单,它具有高性能、高可靠、无中心、免维护等优点。 大家担心的是这么简单的文件系统,靠不靠谱,可不

小张 3.3k Jan 8, 2023
A tool for moving files into directories by file extensions

The tool for moving files into directories by file extensions Example before moving structure: moving into same extension dir result: moving into diff

Uladzislau Jum 0 Dec 6, 2021
A command line tool for mainly exporting logbook records from Google Spreadsheet to PDF file in EASA format

Logbook CLI This is a command line tool for mainly exporting logbook records from Google Spreadsheet to PDF file in EASA format. It also supports rend

Vladimir Simakhin 0 Feb 6, 2022
searchHIBP is a golang tool that implements binary search over a hash ordered binary file.

searchHIBP is a golang tool that implements binary search over a hash ordered binary file.

fblz 0 Nov 9, 2021
A database/file backup tool with web interfaces

backup-x 带Web界面的数据库/文件备份增强工具。原理:执行自定义shell命令输出文件,增强备份功能。

null 108 Dec 26, 2022
A useful file search tool

go-find 花了半天时间写的一个的文件名、文件内容搜索工具,主要是为了hvv中快速发现敏感文件、配置文件等。

null 46 Sep 22, 2022
Ghostinthepdf - This is a small tool that helps to embed a PostScript file into a PDF

This is a small tool that helps to embed a PostScript file into a PDF in a way that GhostScript will run the PostScript code during the

Emil Lerner 135 Dec 20, 2022
A small tool for sending a single file to another machine

file-traveler A small tool for sending a single file to another machine. Build g

Vence Lam 1 Dec 28, 2021
Simple go script that converts csv file into a json document

csv-go-parser Simple go script that converts csv file into a json document. CSV Input: id,first_name,last_name,email,avatar,ip_address 1,Pauline,Hirth

Martin Patino 1 Jun 4, 2022
Dontfile-simple - The simplest version of an online file manager

dontfile-simple The simplest version of an online file manager. Built With Golan

null 0 Jan 12, 2022