Read whole object payload

Signed-off-by: Alex Vanin <a.vanin@yadro.com>
This commit is contained in:
Alexey Vanin 2024-11-11 11:28:57 +03:00
parent c3416e9184
commit acd4729193
2 changed files with 19 additions and 3 deletions

View file

@ -191,6 +191,14 @@ func (h *handler) PutObjectHandler(w http.ResponseWriter, r *http.Request) {
reqInfo = middleware.GetReqInfo(ctx)
)
payload, err := io.ReadAll(r.Body)
if err != nil {
h.logAndSendError(ctx, w, "could not read payload data", reqInfo, err)
return
}
r.Body = io.NopCloser(bytes.NewReader(payload))
bktInfo, err := h.getBucketAndCheckOwner(r, reqInfo.BucketName)
if err != nil {
h.logAndSendError(ctx, w, "could not get bucket objInfo", reqInfo, err)
@ -433,6 +441,14 @@ func (h *handler) PostObject(w http.ResponseWriter, r *http.Request) {
metadata = make(map[string]string)
)
payload, err := io.ReadAll(r.Body)
if err != nil {
h.logAndSendError(ctx, w, "could not read payload data", reqInfo, err)
return
}
r.Body = io.NopCloser(bytes.NewReader(payload))
policy, err := checkPostPolicy(r, reqInfo, metadata)
if err != nil {
h.logAndSendError(ctx, w, "failed check policy", reqInfo, err)

View file

@ -522,9 +522,9 @@ func (n *Layer) objectPutAndHash(ctx context.Context, prm frostfs.PrmObjectCreat
hash.Write(buf)
md5Hash.Write(buf)
})
if threshold := n.features.ThresholdMaxSizeForPut(); threshold > 0 {
prm.Payload = wrapReaderThreshold(prm.Payload, int(threshold))
}
// if threshold := n.features.ThresholdMaxSizeForPut(); threshold > 0 {
// prm.Payload = wrapReaderThreshold(prm.Payload, int(threshold))
// }
res, err := n.frostFS.CreateObject(ctx, prm)
if err != nil {
if _, errDiscard := io.Copy(io.Discard, prm.Payload); errDiscard != nil {