OSS does not restrict file types or sizes by default. To control what users can upload, configure the filters property in your Plupload uploader instance. This lets you restrict accepted file extensions, cap file size, and block duplicate selections on the client side before the upload reaches OSS.
Prerequisites
Before you begin, ensure that you have:
Completed the JavaScript client-side signature direct transfer setup. See Add signatures on the client by using JavaScript and upload data to OSS
Configure upload filters
Open
upload.js.Add the
filtersblock inside yourvar uploader = new plupload.Uploaderinstance:filters: { mime_types: [ // Accept images and ZIP archives only. { title: "Image files", extensions: "jpg,gif,png,bmp" }, { title: "Zip files", extensions: "zip" } ], // Reject files larger than 400 KB. max_file_size: "400kb", // Block duplicate file selections. prevent_duplicates: true },The three filter properties control different aspects of file selection:
Property Type Description mime_typesArray Restricts selectable files to the specified extensions. Each entry maps a display title to a comma-separated list of extensions. Files with other extensions cannot be selected in the file picker. max_file_sizeString Sets the maximum allowed file size. Accepts values such as "400kb"or"5mb". Files that exceed this limit cannot be added to the upload queue.prevent_duplicatesBoolean When set to true, prevents the same file from being added to the upload queue more than once.For the full list of supported filter options, see Set upload filter conditions.
Save
upload.js.
Verify the filters
Open index.html in a browser. Click Select File and confirm:
The file picker shows only JPG, GIF, PNG, BMP, and ZIP files.
Files larger than 400 KB cannot be added to the upload queue.
Re-selecting a file already in the queue has no effect.
What's next
Client-side filters rely on browser enforcement and can be bypassed by direct HTTP requests. To enforce upload constraints at the server level, configure a POST policy on your OSS bucket. See Configure policies for POST requests in OSS.