Documentation
¶
Overview ¶
Package upload provides a prefab plugin that adds an HTTP handler for uploading files. The handler accepts multipart form data, buffers the file in memory, and then persists the file to a storage backend.
Files are stored using a salted hash of their contents. This means the file is content addressable, but not guessable by someone without the salt.
The plugin optionally integrates with the authz plugin to enforce access controls. For upload, the query parameters "domain" and "folder" may be passed. "domain" would typically be a workspace, organization, or high-level grouping. "folder" might be a user id, a project id, or some other entity that governs upload and download rights.
Roadmap for this plugin: - Support streaming (uploads and backends) to reduce memory usage.
Index ¶
- Constants
- Variables
- type Backend
- type FSBackend
- type MemBackend
- type UploadOption
- type UploadPlugin
- type UploadResponse
- type UploadedFile
- func (*UploadedFile) Descriptor() ([]byte, []int)deprecated
- func (x *UploadedFile) GetOriginalName() string
- func (x *UploadedFile) GetUploadPath() string
- func (*UploadedFile) ProtoMessage()
- func (x *UploadedFile) ProtoReflect() protoreflect.Message
- func (x *UploadedFile) Reset()
- func (x *UploadedFile) String() string
Constants ¶
const ( // Constant name for identifying the upload plugin. PluginName = "upload" // authz action for storing files. SaveAction = "upload.save" // authz action for downloading files. DownloadAction = "upload.download" // authz object key used to scope RoleDescribers. ObjectKey = "upload" )
Variables ¶
var File_plugins_upload_upload_proto protoreflect.FileDescriptor
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend interface {
// Save saves the file to the backend.
Save(path string, data []byte) error
// Get retrieves the file from the backend.
Get(path string) ([]byte, error)
}
Backend is an interface for storing and retrieving files.
type FSBackend ¶
type FSBackend struct {
// contains filtered or unexported fields
}
FSBackend is a Backend that stores files on the filesystem.
type MemBackend ¶
type MemBackend struct {
// contains filtered or unexported fields
}
MemBackend is a Backend that stores files in memory. Intended for testing and development. Not threadsafe.
type UploadOption ¶
type UploadOption func(*UploadPlugin)
UploadOptions customize the configuration of the upload plugin.
func WithBackend ¶
func WithBackend(be Backend) UploadOption
WithBackend configures the storage backend to use.
func WithValidTypes ¶
func WithValidTypes(types ...string) UploadOption
WithValidTypes configures the valid file types that can be uploaded. Overriding any values from the configuration.
type UploadPlugin ¶
type UploadPlugin struct {
// contains filtered or unexported fields
}
UploadPlugin provides an HTTP handler for uploading files.
func (*UploadPlugin) OptDeps ¶
func (p *UploadPlugin) OptDeps() []string
From prefab.OptionalDependentPlugin.
func (*UploadPlugin) ServerOptions ¶
func (p *UploadPlugin) ServerOptions() []prefab.ServerOption
From prefab.OptionProvider.
type UploadResponse ¶
type UploadResponse struct {
Files []*UploadedFile `protobuf:"bytes,1,rep,name=files,proto3" json:"files,omitempty"`
// contains filtered or unexported fields
}
Response from calling the upload endpoint.
func (*UploadResponse) Descriptor
deprecated
func (*UploadResponse) Descriptor() ([]byte, []int)
Deprecated: Use UploadResponse.ProtoReflect.Descriptor instead.
func (*UploadResponse) GetFiles ¶
func (x *UploadResponse) GetFiles() []*UploadedFile
func (*UploadResponse) ProtoMessage ¶
func (*UploadResponse) ProtoMessage()
func (*UploadResponse) ProtoReflect ¶
func (x *UploadResponse) ProtoReflect() protoreflect.Message
func (*UploadResponse) Reset ¶
func (x *UploadResponse) Reset()
func (*UploadResponse) String ¶
func (x *UploadResponse) String() string
type UploadedFile ¶
type UploadedFile struct {
// The original filename of the uploaded file, so that the client can match
// the uploaded file with the file that was uploaded.
OriginalName string `protobuf:"bytes,1,opt,name=original_name,json=originalName,proto3" json:"original_name,omitempty"`
// The path where the file was uploaded to.
UploadPath string `protobuf:"bytes,2,opt,name=upload_path,json=uploadPath,proto3" json:"upload_path,omitempty"`
// contains filtered or unexported fields
}
func (*UploadedFile) Descriptor
deprecated
func (*UploadedFile) Descriptor() ([]byte, []int)
Deprecated: Use UploadedFile.ProtoReflect.Descriptor instead.
func (*UploadedFile) GetOriginalName ¶
func (x *UploadedFile) GetOriginalName() string
func (*UploadedFile) GetUploadPath ¶
func (x *UploadedFile) GetUploadPath() string
func (*UploadedFile) ProtoMessage ¶
func (*UploadedFile) ProtoMessage()
func (*UploadedFile) ProtoReflect ¶
func (x *UploadedFile) ProtoReflect() protoreflect.Message
func (*UploadedFile) Reset ¶
func (x *UploadedFile) Reset()
func (*UploadedFile) String ¶
func (x *UploadedFile) String() string