Go to file
Darko Luketic 30d8d4d193 renamed package, added defer ms.Close() 2015-05-21 21:31:05 +02:00
README.md update README.md 2015-03-21 16:03:59 +01:00
file.go renamed package, added defer ms.Close() 2015-05-21 21:31:05 +02:00
helpers.go initial 2015-03-21 16:02:38 +01:00

README.md

file

Upload, Download, Delete and list files (optional) as JSON

How

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