aboutsummaryrefslogtreecommitdiff
path: root/mediaapi
diff options
context:
space:
mode:
authorS7evinK <2353100+S7evinK@users.noreply.github.com>2022-04-04 10:32:53 +0200
committerGitHub <noreply@github.com>2022-04-04 10:32:53 +0200
commita0f5d8e1a503b3932b07e0786a92c64a9bbda88a (patch)
tree2452aa58ed56f6519f331c9316a13579030ddd7f /mediaapi
parentcd8fac152eb2ea9165646e08bd87e3e95bd4706a (diff)
Fix unlimitedSize uploads (#2317)
Diffstat (limited to 'mediaapi')
-rw-r--r--mediaapi/routing/upload.go2
-rw-r--r--mediaapi/routing/upload_test.go22
2 files changed, 23 insertions, 1 deletions
diff --git a/mediaapi/routing/upload.go b/mediaapi/routing/upload.go
index ecdab219..f762b2ff 100644
--- a/mediaapi/routing/upload.go
+++ b/mediaapi/routing/upload.go
@@ -169,7 +169,7 @@ func (r *uploadRequest) doUpload(
}
// Check if temp file size exceeds max file size configuration
- if bytesWritten > types.FileSizeBytes(*cfg.MaxFileSizeBytes) {
+ if *cfg.MaxFileSizeBytes > 0 && bytesWritten > types.FileSizeBytes(*cfg.MaxFileSizeBytes) {
fileutils.RemoveDir(tmpDir, r.Logger) // delete temp file
return requestEntityTooLargeJSONResponse(*cfg.MaxFileSizeBytes)
}
diff --git a/mediaapi/routing/upload_test.go b/mediaapi/routing/upload_test.go
index 032437b5..e81254f3 100644
--- a/mediaapi/routing/upload_test.go
+++ b/mediaapi/routing/upload_test.go
@@ -36,6 +36,7 @@ func Test_uploadRequest_doUpload(t *testing.T) {
}
maxSize := config.FileSizeBytes(8)
+ unlimitedSize := config.FileSizeBytes(0)
logger := log.New().WithField("mediaapi", "test")
testdataPath := filepath.Join(wd, "./testdata")
@@ -117,6 +118,27 @@ func Test_uploadRequest_doUpload(t *testing.T) {
},
want: requestEntityTooLargeJSONResponse(maxSize),
},
+ {
+ name: "upload ok with unlimited filesize",
+ args: args{
+ ctx: context.Background(),
+ reqReader: strings.NewReader("test test test"),
+ cfg: &config.MediaAPI{
+ MaxFileSizeBytes: &unlimitedSize,
+ BasePath: config.Path(testdataPath),
+ AbsBasePath: config.Path(testdataPath),
+ DynamicThumbnails: false,
+ },
+ db: db,
+ },
+ fields: fields{
+ Logger: logger,
+ MediaMetadata: &types.MediaMetadata{
+ MediaID: "1339",
+ UploadName: "test fail",
+ },
+ },
+ },
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {