All Products
Search
Document Center

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

Last Updated:Oct 26, 2021

Overview

Alibaba Cloud Object Storage Service (OSS) itself does not limit the type and size of files to be uploaded. Due to business needs, how to set only upload images, the size of uploaded files, and no repeated uploads. This topic describes how to limit the type and size of an uploaded file when you upload the file by using the JavaScript client-side signature direct transfer method (Web-side direct transfer).

Details

After you complete the installation of the JavaScript client-side signature direct transfer environment, you can use the filters property of Plupload to set the filter conditions for uploading, such as setting the type of image to upload and the size of the uploaded file. For more information about how to configure direct transmission of JavaScript client signatures, see Direct transmission of JavaScript client signatures.

  1. Open the upload.js file.
  2. Add the following fields in the var uploader = new plupload.Uploader instance and save them. For more information, see Set upload filter conditions.
    filters: {
    mime_types : [
    // Only images and ZIP files can be uploaded.
    {title : "Image files", extensions : "jpg,gif,png,bmp" },
    { title : "Zip files", extensions : "zip" }
    ],
    // You can upload a maximum of 400KB files.
    max_file_size : '400kb',
    // Duplicate files are not allowed to be selected.
    prevent_duplicates : true 
        },
    Note:
    • mime_types: limits the suffix of uploaded files.
    • max_file_size: limits the size of uploaded files.
    • prevent_duplicates: The limit cannot be repeated.
  3. Open the index.html file and test the upload. After you click Select File, you can select only JPG, GIF, PNG, BMP, and ZIP files. The size of the files cannot exceed 400KB.

References

For more information, see Configure policies for POST requests in OSS.

Applicable scope

  • OSS