Fix unlimitedSize uploads (#2317)

This commit is contained in:
S7evinK 2022-04-04 10:32:53 +02:00 committed by GitHub
parent cd8fac152e
commit a0f5d8e1a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -169,7 +169,7 @@ func (r *uploadRequest) doUpload(
} }
// Check if temp file size exceeds max file size configuration // 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 fileutils.RemoveDir(tmpDir, r.Logger) // delete temp file
return requestEntityTooLargeJSONResponse(*cfg.MaxFileSizeBytes) return requestEntityTooLargeJSONResponse(*cfg.MaxFileSizeBytes)
} }

View File

@ -36,6 +36,7 @@ func Test_uploadRequest_doUpload(t *testing.T) {
} }
maxSize := config.FileSizeBytes(8) maxSize := config.FileSizeBytes(8)
unlimitedSize := config.FileSizeBytes(0)
logger := log.New().WithField("mediaapi", "test") logger := log.New().WithField("mediaapi", "test")
testdataPath := filepath.Join(wd, "./testdata") testdataPath := filepath.Join(wd, "./testdata")
@ -117,6 +118,27 @@ func Test_uploadRequest_doUpload(t *testing.T) {
}, },
want: requestEntityTooLargeJSONResponse(maxSize), 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 { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {