coquelicot

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2015 License: MIT Imports: 22 Imported by: 0

README

Coquelicot

Coquelicot is an easy to use server-side upload service written in Go.

It is compatible with the jQuery-File-Upload widget and supports chunked and resumable file upload.

Using Coquelicot, you can add upload functionality to your project very easily. Just download and unzip the Coquelicot binary distribution for your OS and configure the jQuery-File-Upload widget.

logo

Server Setup

You can use a binary release or get the project if you have a working Go installation.

Binary Release

Grab the latest binary release for you system. Unzip it and run

$ ./coquelicot -storage /tmp/files -host localhost:9073

to store uploaded files into /tmp/files and make the application listen on the loopback interface port 9073 (run coquelicot.exe on Windows).

Source Release

Grab the latest stable version with:

$ go get gopkg.in/gotsunami/coquelicot.v1

See the API documentation.

jQuery-File-Upload Setup (Client)

The fileupload object needs the xhrFields, maxChunkSize and add fields to be defined.

  • xhrFields: enables sending of cross-domain cookies, which is required to properly handle chunks of data server-side
  • maxChunkSize: enables uploading chunks of file
  • add: overwrites the default add handler to support resuming file upload

Download the latest release of jQuery-File-Upload, edit the js/main.js file in the distribution and make the fileupload initialization look like (replacing the localhost:9073 part with the name:port of your server running the coquelicot program):

$('#fileupload').fileupload({
    // Send cross-domain cookies
    xhrFields: {withCredentials: true},
    url: 'http://localhost:9073/files',
    // Chunk size in bytes
    maxChunkSize: 1000000,
    // Enable file resume
    add: function (e, data) {
        var that = this;
        $.ajax({
            url: 'http://localhost:9073/resume',
            xhrFields: {withCredentials: true},
            data: {file: data.files[0].name}
        }).done(function(result) {
            var file = result.file;
            data.uploadedBytes = file && file.size;
            $.blueimp.fileupload.prototype.options.add.call(that, e, data);
        });
    }
});

Documentation

Overview

Package coquelicot provides (chunked) file upload capability (with resume).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Adapt

func Adapt(h http.Handler, adapters ...Adapter) http.Handler

func Convert

func Convert(b bool) option

Convert generates an image thumbnail using ImageMagick.

func Verbosity

func Verbosity(level int) option

Verbosity sets verbosity level (1 to 3).

Types

type Adapter

type Adapter func(http.Handler) http.Handler

func CORSMiddleware

func CORSMiddleware() Adapter

func LogMiddleware

func LogMiddleware(logger *log.Logger) Adapter

type H

type H map[string]interface{}

type Storage

type Storage struct {
	// contains filtered or unexported fields
}

func NewStorage

func NewStorage(rootDir string) *Storage

func (*Storage) Option

func (s *Storage) Option(opts ...option)

func (*Storage) ResumeHandler

func (s *Storage) ResumeHandler(w http.ResponseWriter, r *http.Request)

ResumeHandler allows resuming a file upload. func (s *Storage) ResumeHandler(c *gin.Context) {

func (*Storage) StorageDir

func (s *Storage) StorageDir() string

func (*Storage) UploadHandler

func (s *Storage) UploadHandler(w http.ResponseWriter, r *http.Request)

UploadHandler is the endpoint for uploading and storing files. func (s *Storage) UploadHandler(c *gin.Context) {

Directories

Path Synopsis
bin

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL