Documentation ¶
Overview ¶
Package uploadhandler implements a middleware plugin for HTTP file uploads.
Copyright © 2019, 2022 M.Watermann, 10247 Berlin, Germany All rights reserved EMail : <support@mwat.de>
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
You should have received a copy of the GNU General Public License along with this program. If not, see the [GNU General Public License](http://www.gnu.org/licenses/gpl.html) for details.
Copyright © 2019, 2022 M.Watermann, 10247 Berlin, Germany All rights reserved EMail : <support@mwat.de>
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Wrap ¶
func Wrap(aHandler http.Handler, aDestDir, aFieldName, aUpURL, aNextURL string, aMaxSize int64, aPager errorhandler.TErrorPager) http.Handler
Wrap returns a handler function that includes upload handling, wrapping the given `aHandler` and calling it internally.
`aHandler` The previous handler responding to the HTTP request. `aDestDir` Is the directory to place the uploaded files. `aFieldName` The name/ID of the form/input field holding the uploaded file. `aUpURL` The URL uploads are POSTed to. `aNextURL` The URL to redirect the user after a successful upload. `aMaxSize` The max. accepted size of uploaded files; if the given value is smaller/equal to zero then a maximal filesize of 8 MB is used. `aPager` Optional provider of customised error message pages
(or `nil` if not needed).
Types ¶
type TUploadHandler ¶
type TUploadHandler struct {
// contains filtered or unexported fields
}
TUploadHandler embeds a `TErrorPager` which provides error page handling.
func NewHandler ¶
func NewHandler(aDestDir, aFieldName string, aMaxSize int64) (rHandler *TUploadHandler)
NewHandler returns a new `TUploadHandler` instance.
If the `aMaxSize` value is smaller/equal to zero a maximal filesize of 8 MB is used.
`aDestDir` is the directory to place the uploaded files. `aFieldName` the name/ID of the form/input holding the uploaded file. `aMaxSize` the max. accepted size of uploaded files.
func (*TUploadHandler) ServeUpload ¶
func (uh *TUploadHandler) ServeUpload(aWriter http.ResponseWriter, aRequest *http.Request) (rCause string, rCode int)
ServeUpload handles the incoming file upload.
The first return value (`rCause`) will provide a short error message and the second return value (`rCode`) the HTTP status code. If that code is `200` (i.e. everything went well) then the message return value (`rCause`) will hold the path/file name of the saved file.
`aWriter` writes the response to the remote user. `aRequest` is the incoming upload request.