Documentation ¶
Index ¶
- func GetFileName(r *http.Request, fileName string) (string, error)
- func ImageTestHelper(t *testing.T) (*io.PipeReader, *multipart.Writer)
- type FileManager
- func (f *FileManager) Delete(fileName string, id uint) error
- func (f *FileManager) DeleteEntityByID(id uint) error
- func (f *FileManager) Get(fileName string, id uint) string
- func (f *FileManager) GetEntityDirPath(id uint) string
- func (f *FileManager) GetEntityFilePath(fullEntityDirPath string, fileName string) string
- func (f *FileManager) GetEntityURL(fileName string, id uint) string
- func (f *FileManager) ReceiveMultiPartFormDataAndSaveToDir(r *http.Request, field string, id uint) error
- func (f *FileManager) Update(fileName string, id uint, newFileName string) error
- func (f *FileManager) Upload(w http.ResponseWriter, r *http.Request, id uint, formName string) (string, error)
- type FileUpload
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ImageTestHelper ¶ added in v0.0.8
ImageTestHelper Adds an image form file to the handler
Types ¶
type FileManager ¶
type FileManager struct { *FileUpload TableName string }
func (*FileManager) Delete ¶
func (f *FileManager) Delete(fileName string, id uint) error
Delete Deletes the file from the entity file path
func (*FileManager) DeleteEntityByID ¶
func (f *FileManager) DeleteEntityByID(id uint) error
DeleteEntityByID Deletes a single entity by a UUID
func (*FileManager) Get ¶
func (f *FileManager) Get(fileName string, id uint) string
Get Gets the full file path including the filename
func (*FileManager) GetEntityDirPath ¶
func (f *FileManager) GetEntityDirPath(id uint) string
GetEntityDirPath Gets the full entity file path only (does not include the filename)
func (*FileManager) GetEntityFilePath ¶
func (f *FileManager) GetEntityFilePath(fullEntityDirPath string, fileName string) string
GetEntityFilePath Get the full path which is constructed of the following: upload path + entity name + plus the primary id + the filename e.g. `./assets/uploads/users/1/cats.jpg`
func (*FileManager) GetEntityURL ¶ added in v0.0.3
func (f *FileManager) GetEntityURL(fileName string, id uint) string
GetEntityURL GetEntityUrl gets the full url
func (*FileManager) ReceiveMultiPartFormDataAndSaveToDir ¶ added in v0.0.8
func (f *FileManager) ReceiveMultiPartFormDataAndSaveToDir(r *http.Request, field string, id uint) error
ReceiveMultiPartFormDataAndSaveToDir Handles a file uploaded via multipart form request over http The field argument is the form field's name
func (*FileManager) Update ¶
func (f *FileManager) Update(fileName string, id uint, newFileName string) error
Update Updates only the filename not the file (Use Upload to update the file)
func (*FileManager) Upload ¶
func (f *FileManager) Upload(w http.ResponseWriter, r *http.Request, id uint, formName string) (string, error)
Upload Uploads & stores the file on your server. If there is an error then the return value of string will be an empty string. If there are no errors to return the string will be the full path of with filename.
type FileUpload ¶
type FileUpload struct { UploadDir string MaxFileSize uint8 FileTypes []string URL string // contains filtered or unexported fields }
func (*FileUpload) Init ¶
func (f *FileUpload) Init(tableName string) (*FileManager, error)
Init is a factory function that returns a pointer to FileManager. tableName is the name of the entity associated with a database table name.