minio upload
This commit is contained in:
parent
5aaa644fc5
commit
67e913ff3a
|
@ -11,8 +11,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Bucket names
|
// Bucket names
|
||||||
var (
|
const (
|
||||||
RecipeImg string = "recipeimg"
|
recipeImgBucket string = "recipeimg"
|
||||||
)
|
)
|
||||||
|
|
||||||
const location string = "eu_ru"
|
const location string = "eu_ru"
|
||||||
|
@ -65,7 +65,7 @@ func New(ctx context.Context, addr, user, password string) (*ObjStorage, error)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// Upload file to bucket
|
// Upload file to bucket
|
||||||
func (o *ObjStorage) UploadFile(ctx context.Context, bucketName string, objectName string, fileBuffer io.Reader, contentType string, fileSize int64) error {
|
func (o *ObjStorage) uploadFile(ctx context.Context, bucketName string, objectName string, fileBuffer io.Reader, contentType string, fileSize int64) error {
|
||||||
const op = "minio.UploadFile"
|
const op = "minio.UploadFile"
|
||||||
// Upload the zip file with PutObject
|
// Upload the zip file with PutObject
|
||||||
info, err := o.minio.PutObject(ctx, bucketName, objectName, fileBuffer, fileSize, minio.PutObjectOptions{ContentType: contentType})
|
info, err := o.minio.PutObject(ctx, bucketName, objectName, fileBuffer, fileSize, minio.PutObjectOptions{ContentType: contentType})
|
||||||
|
@ -77,7 +77,7 @@ func (o *ObjStorage) UploadFile(ctx context.Context, bucketName string, objectNa
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get file from bucket
|
// Get file from bucket
|
||||||
func (o *ObjStorage) GetFile(ctx context.Context, bucketName string, objectName string) (*minio.Object, error) {
|
func (o *ObjStorage) getFile(ctx context.Context, bucketName string, objectName string) (*minio.Object, error) {
|
||||||
const op = "minio.GetFile"
|
const op = "minio.GetFile"
|
||||||
// Get object from minio
|
// Get object from minio
|
||||||
minio_obj, err := o.minio.GetObject(ctx, bucketName, objectName, minio.GetObjectOptions{Checksum: true})
|
minio_obj, err := o.minio.GetObject(ctx, bucketName, objectName, minio.GetObjectOptions{Checksum: true})
|
||||||
|
@ -88,7 +88,7 @@ func (o *ObjStorage) GetFile(ctx context.Context, bucketName string, objectName
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete file from bucket
|
// Delete file from bucket
|
||||||
func (o *ObjStorage) DelFile(ctx context.Context, bucketName string, objectName string) error {
|
func (o *ObjStorage) delFile(ctx context.Context, bucketName string, objectName string) error {
|
||||||
const op = "minio.DelFile"
|
const op = "minio.DelFile"
|
||||||
err := o.minio.RemoveObject(ctx, bucketName, objectName, minio.RemoveObjectOptions{ForceDelete: true})
|
err := o.minio.RemoveObject(ctx, bucketName, objectName, minio.RemoveObjectOptions{ForceDelete: true})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -96,3 +96,7 @@ func (o *ObjStorage) DelFile(ctx context.Context, bucketName string, objectName
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (o *ObjStorage) SaveRecipeImage(ctx context.Context) error {
|
||||||
|
o.uploadFile(ctx, recipeImgBucket)
|
||||||
|
}
|
||||||
|
|
|
@ -205,7 +205,7 @@ func GetRecipe(r *models.Recipe) error {
|
||||||
// fmt.Printf("%+v\n", r)
|
// fmt.Printf("%+v\n", r)
|
||||||
// fmt.Println("-------------------")
|
// fmt.Println("-------------------")
|
||||||
// check recipe exists
|
// check recipe exists
|
||||||
ex, err := postgres.DB.RecipeExists(r.Title)
|
ex, err := postgres.DB.RecipeExists(r.Title) // interface!
|
||||||
if err != nil || ex {
|
if err != nil || ex {
|
||||||
return fmt.Errorf("%s: %w", op, fmt.Errorf("recipe already exists"))
|
return fmt.Errorf("%s: %w", op, fmt.Errorf("recipe already exists"))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue