UploadFile

package
v0.1.43 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2021 License: BSD-3-Clause Imports: 20 Imported by: 0

README

File Upload

This module assumes that you wish to upload a file and send the file to amazon S3.

import (
	...
	"gitlab.com/pschlump/PureImaginationServer/awss3"
	...
	"gitlab.com/pschlump/PureImaginationServer/UploadFile"
	...
)

Include in the global configuration:

type ConfigData struct {

	...

	UploadFile.UploadFileCfg

	...

}

The call to setup the file uploaded (usually called in the main)

	...

	// ------------------------------------------------------------------------------
	// Setup connection to S3
	// ------------------------------------------------------------------------------
	if DbOn["push-to-aws"] {
		awsSession = awss3.SetupS3(gCfg.S3_bucket, gCfg.S3_region, DbOn)
	}

	// ------------------------------------------------------------------------------
	// Configure Upload File
	// ------------------------------------------------------------------------------
	UploadFile.Setup(&(gCfg.UploadFileCfg), DbOn, logFilePtr, awsSession)

	...

Also you need the endpoint in the mux:

	mux.Handle("/upload", http.HandlerFunc(UploadFile.UploadFileClosure(gCfg.UploadPath))).NoDoc()

The upload can be tested with:


$ curl -F file=@file.txt http://example.com/upload

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DbFlags map[string]bool
View Source
var MimeToExtMap = map[string]string{
	"image/jpeg":        ".jpg",
	"image/png":         ".png",
	"image/webp":        ".webp",
	"image/heic":        ".heic",
	"image/heif":        ".heic",
	"image/gif":         ".gif",
	"image/svg":         ".svg",
	"image/svg+xml":     ".svg",
	"image/apng":        ".apng",
	"image/avif":        ".avif",
	"text/plain":        ".txt",
	"audio/wav":         ".wav",
	"audio/mp3":         ".mp3",
	"application/pdf":   ".pdf",
	"application/json":  ".json",
	"application/csv":   ".csv",
	"application/excel": ".xls",
	"application/xml":   ".xml",
}

------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------

New

------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------

Functions

func AddFileToZip

func AddFileToZip(zipWriter *zip.Writer, filename string) error

func EndFileSetClosure

func EndFileSetClosure(pth string) func(www http.ResponseWriter, req *http.Request)

func GenUUID

func GenUUID() string

func GetExtFromMime

func GetExtFromMime(mimeType string) (rv string)

func ListFileSetClosure

func ListFileSetClosure(baseURL, pth string) func(www http.ResponseWriter, req *http.Request)

func MarkFilesWithTxClosure

func MarkFilesWithTxClosure(pth string) func(www http.ResponseWriter, req *http.Request)

func Setup

func Setup(cfg *UploadFileCfg, dbf map[string]bool, lfp *os.File, as *session.Session)

func StartFileSetClosure

func StartFileSetClosure(pth string) func(www http.ResponseWriter, req *http.Request)

func UploadFileClosure

func UploadFileClosure(pth string) func(www http.ResponseWriter, req *http.Request)

func UploadFileSetClosure

func UploadFileSetClosure(pth string) func(www http.ResponseWriter, req *http.Request)

func ZipFiles

func ZipFiles(filename string, files []string) error

ZipFiles compresses one or many files into a single zip archive file. Param 1: filename is the output zip file's name. Param 2: files is a list of files to add to the zip.

Types

type FileListType

type FileListType struct {
	Name    string `json:"name"`
	FileUrl string `json:"url"`
	AwsUrl  string `json:"aws_url"`
}

type MetaDataFile

type MetaDataFile struct {
	Hash         string `json:"hash"`
	MimeType     string `json:"mimeType"`
	OrigFileName string `json:"orig_file_name"`
}

type UploadFileCfg

type UploadFileCfg struct {

	// Path where files are temporary uploaded to
	// Also where bulk load will pull input:__file_name__ from
	UploadPath    string `json:"upload_path" default:"./www/files"`
	URLUploadPath string `json:"url_upload_path" default:"/files"`
	UploadTable   string `json:"upload_table" default:"document"`

	BaseAwsServerURL string `json:"base_aws_server_url" default:"http://localhost:8080"`

	// added - replaces debug flag
	PushToAWS string `json:"push_to_aws" default:"yes"`

	S3Perms string `json:"s3_perms" defaulit:"private"`
}

Jump to

Keyboard shortcuts

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