All Products
Search
Document Center

Object Storage Service:How to Limit the Type and Size of Uploaded Files When OSS Signs Direct Transfer Files Through a JavaScript Client

Last Updated:Mar 20, 2026

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:

Configure upload filters

  1. Open upload.js.

  2. Add the filters block inside your var uploader = new plupload.Uploader instance:

       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:

    PropertyTypeDescription
    mime_typesArrayRestricts 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_sizeStringSets 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_duplicatesBooleanWhen 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.

  3. 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.

References