File uploads, mostly. Also added extra behavior to addCharacter.
the build was successful

This commit is contained in:
2019-08-31 22:46:55 +02:00
parent 8a313b3bb2
commit c8ced52e1a
17 changed files with 175 additions and 25 deletions
+15 -10
View File
@@ -25,29 +25,27 @@ func (client *Client) MaxSize() int64 {
// UploadFile uploads the file to the space. This does not do any checks on it, so the endpoints should
// ensure that's all okay.
func (client *Client) UploadFile(ctx context.Context, folder string, name string, mimeType string, reader io.Reader, size int64) (string, error) {
path := folder + "/" + name
func (client *Client) UploadFile(ctx context.Context, name string, mimeType string, reader io.Reader, size int64) error {
if size > client.maxSize {
return "", errors.New("file is too big")
return errors.New("file is too big")
}
_, err := client.s3.PutObjectWithContext(ctx, client.bucket, client.spaceRoot+"/"+path, reader, size, minio.PutObjectOptions{
_, err := client.s3.PutObjectWithContext(ctx, client.bucket, client.spaceRoot+"/"+name, reader, size, minio.PutObjectOptions{
ContentType: mimeType,
UserMetadata: map[string]string{
"x-amz-acl": "public-read",
},
})
if err != nil {
return "", err
return err
}
_, err = client.s3.StatObject(client.bucket, client.spaceRoot+"/"+path, minio.StatObjectOptions{})
_, err = client.s3.StatObject(client.bucket, client.spaceRoot+"/"+name, minio.StatObjectOptions{})
if err != nil {
return "", err
return err
}
return path, nil
return nil
}
// RemoveFile removes a file from the space
@@ -83,9 +81,16 @@ func Connect(cfg config.Space) (*Client, error) {
return nil, errors.New("bucket not found")
}
urlRoot := cfg.URLRoot
if urlRoot == "" {
urlRoot = fmt.Sprintf("https://%s.%s/%s/", cfg.Bucket, cfg.Host, cfg.Root)
} else {
urlRoot += "/" + cfg.Root + "/"
}
return &Client{
bucket: cfg.Bucket,
urlRoot: fmt.Sprintf("https://%s.%s/%s/", cfg.Bucket, cfg.Host, cfg.Root),
urlRoot: urlRoot,
spaceRoot: cfg.Root,
maxSize: cfg.MaxSize,
s3: client,