
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
a tool for handling file uploads for http servers
makes it easier to make operations with files from the http request.
go get github.com/xis/baraka
func main() {
// create a parser
parser := baraka.NewParser(baraka.ParserOptions{
MaxFileSize: 5 << 20,
MaxFileCount: 5,
MaxParseCount: 5,
})
router := gin.Default()
router.POST("/upload", func(c *gin.Context) {
// parsing
p, err := parser.Parse(c.Request)
if err != nil {
fmt.Println(err)
}
// saving
err = p.Save("image_", "./")
if err != nil {
fmt.Println(err)
}
// getting the part in the []byte format
parts := p.Content()
buf := parts[0].Content
fmt.Println(len(buf))
})
router.Run()
}
you can use baraka with the other http server libraries, just pass the http.Request to the parser.Parse function.
filter function is a custom function which filters the files that comes from the request. for example you can read file bytes and identify the file, return true if you wanna pass the file, return false if you don't.
func main() {
// create a parserr
parser := baraka.NewParser(baraka.ParserOptions{
// passing filter function
Filter: func(data []byte) bool {
// get first 512 bytes for checking content type
buf := data[:512]
// detect the content type
fileType := http.DetectContentType(buf)
// if it is jpeg then pass the file
if fileType == "image/jpeg" {
return true
}
// if not then don't pass
return false
},
})
p, err := parser.Parse(c.Request)
if err != nil {
fmt.Println(err)
}
// prints filenames
fmt.Println(p.Filenames())
// prints total files count
fmt.Println(p.Length())
// prints content types of files
fmt.Println(p.ContentTypes())
p, err := parser.Parse(c.Request)
if err != nil {
fmt.Println(err)
}
jsonStrings, err := p.GetJSON()
if err != nil {
fmt.Println(err)
}
v1.1.1 Handling file uploads simple and memory friendly in Go with Baraka
i will make a blog post for v1.2.0
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.
FAQs
Unknown package
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.