From cfd23c05b45e3c7ef9e326323b3d767c3411a56f Mon Sep 17 00:00:00 2001 From: Andy Hsu Date: Thu, 27 Jul 2023 19:26:22 +0800 Subject: [PATCH] fix(139): upload empty file (close #4711) --- drivers/139/driver.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/139/driver.go b/drivers/139/driver.go index c8935b2c..52cbc47c 100644 --- a/drivers/139/driver.go +++ b/drivers/139/driver.go @@ -300,6 +300,9 @@ func (d *Yun139) Put(ctx context.Context, dstDir model.Obj, stream model.FileStr var partSize = getPartSize(stream.GetSize()) part := (stream.GetSize() + partSize - 1) / partSize + if part == 0 { + part = 1 + } for i := int64(0); i < part; i++ { if utils.IsCanceled(ctx) { return ctx.Err() @@ -331,13 +334,11 @@ func (d *Yun139) Put(ctx context.Context, dstDir model.Obj, stream model.FileStr if err != nil { return err } + _ = res.Body.Close() log.Debugf("%+v", res) - if res.StatusCode != http.StatusOK { return fmt.Errorf("unexpected status code: %d", res.StatusCode) } - - res.Body.Close() } return nil