MCPcopy
hub / github.com/pocketbase/pocketbase / UploadedFileSize

Function UploadedFileSize

core/validators/file.go:18–41  ·  view source on GitHub ↗

UploadedFileSize checks whether the validated [*filesystem.File] size is no more than the provided maxBytes. Example: validation.Field(&form.File, validation.By(validators.UploadedFileSize(1000)))

(maxBytes int64)

Source from the content-addressed store, hash-verified

16//
17// validation.Field(&form.File, validation.By(validators.UploadedFileSize(1000)))
18func UploadedFileSize(maxBytes int64) validation.RuleFunc {
19 return func(value any) error {
20 v, ok := value.(*filesystem.File)
21 if !ok {
22 return ErrUnsupportedValueType
23 }
24
25 if v == nil {
26 return nil // nothing to validate
27 }
28
29 if v.Size > maxBytes {
30 return validation.NewError(
31 "validation_file_size_limit",
32 "Failed to upload {{.file}} - the maximum allowed file size is {{.maxSize}} bytes.",
33 ).SetParams(map[string]any{
34 "file": cutStr(v.OriginalName, 300),
35 "maxSize": maxBytes,
36 })
37 }
38
39 return nil
40 }
41}
42
43// UploadedFileMimeType checks whether the validated [*filesystem.File]
44// mimetype is within the provided allowed mime types.

Callers 2

ValidateValueMethod · 0.92
TestUploadedFileSizeFunction · 0.92

Calls 1

cutStrFunction · 0.70

Tested by 1

TestUploadedFileSizeFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…