id parse on object get and put

This commit is contained in:
Djeeberjr 2021-09-28 16:04:18 +02:00
parent f2a8e0197d
commit 4344bf841c

View File

@ -112,12 +112,21 @@ func httpGetFile(ctx context.Context, rw http.ResponseWriter, r *http.Request) {
}
s3Client := ctx.Value("s3Client").(*minio.Client)
id := r.URL.Query().Get("id")
idString := r.URL.Query().Get("id")
id := types.ParseID(idString)
if id == nil {
// Failed to parse ID
rw.WriteHeader(http.StatusBadRequest)
return
}
log.Debug("S3 call 'StatObject': ", id)
objInfo, err := s3Client.StatObject(context.Background(), "dev", id, minio.GetObjectOptions{})
objInfo, err := s3Client.StatObject(context.Background(), id.Bucket, id.Key, minio.GetObjectOptions{})
if err != nil {
log.Error("Failed to get object info: ", err)
rw.WriteHeader(http.StatusInternalServerError)
return
}
@ -129,9 +138,10 @@ func httpGetFile(ctx context.Context, rw http.ResponseWriter, r *http.Request) {
}
log.Debug("S3 call 'GetObject': ", id)
obj, err := s3Client.GetObject(context.Background(), "dev", id, minio.GetObjectOptions{})
obj, err := s3Client.GetObject(context.Background(), id.Bucket, id.Key, minio.GetObjectOptions{})
if err != nil {
log.Error("Failed to get object: ", err)
rw.WriteHeader(http.StatusInternalServerError)
return
}