file/README.md

82 lines
2.0 KiB
Markdown
Raw Normal View History

2015-03-21 16:02:38 +01:00
# file
Upload, Download, Delete and list files (optional) as JSON
## How
```go
package main
import (
"github.com/gomango/auth"
"github.com/gomango/mblog/blog"
"gopkg.in/mgo.v2"
"log"
"net/http"
)
func main() {
ms, e := mgo.Dial("localhost")
if e != nil {
log.Fatalln(e.Error())
}
authopts := auth.Options{
Host: "file.dev.luketic",
MailFrom: "root@localhost",
MailSupport: "postmaster@localhost",
TemplatePath: "/home/darko/go/src/github.com/gomango/authtemplates",
MailTemplatePath: "/home/darko/go/src/github.com/gomango/authemailtemplates/pongo2",
XSRFkey: auth.GenKey(128),
Database: "testmblog",
Account: "account",
Resetcode: "resetcode",
Profile: "profile",
AESkey: auth.GenKey(32),
HMACkey: auth.GenKey(512),
BcryptPasswordCost: 12,
}
ah := auth.NewAuthHandler(ms, authopts)
http.Handle("/account/", http.StripPrefix("/account/", ah))
fileopts := blog.FileHandlerOptions{
Prefix: "images",
DB: "testfile",
MS: ms,
AllowDuplicate: false,
DisplayIndex: true,
}
fh := blog.NewFileHandler(fileopts)
http.Handle("/images/", http.StripPrefix("/images/", fh))
log.Fatal(http.ListenAndServe(":8080", nil))
}
```
## Interface
PUT and DELETE methods require either
* a cookie with the JWT token acquired by logging in ("token=JWT")
* a HTTP Header Authorization: Bearer JWT
Where JWT is the JWT string
### AllowDuplicate: true
GET /
PUT /
DELETE /{bsonId:[a-fA-F0-9]{24}}
### AllowDuplicate: false
GET /
PUT /
DELETE /{filename:.*}
### Other
For auth methods see https://github.com/gomango/auth
## TODO
* Thumbnails