Restrict Uploads Using File Extensions

This article demonstrates how to restrict file uploads based on file extensions.

Uploads can be restricted as follows:

Using SharinPix Permission Records

SharinPix Permission records consist of the Accepted file types parameter used to specify the type of files that can be uploaded to an album.

The Accepted file types parameter takes as value the list of accepted file extensions separated by a semi-colon. 

For example to restrict uploads to .jpeg, and PDF files, the value will be as follows: .jpeg;application/pdf

Tips:

  • The application/pdf extension is used in the Accepted file types parameter to enable the upload of PDF files.
  • For more information on how to create and assign SharinPix Permission, refer to this article: SharinPix Permission object

Using the upload_accept parameter in Apex Method

Online tokens can be used to restrict uploads based on file extensions using the upload_accept parameter which specifies the type of files that can be uploaded to an album.

For example, to restrict uploads to .png and .jpeg files, the value will be as follows:

'upload_accept' => new List <String> { '.png', '.jpeg' }

The code following code snippet demonstrates how to generate an online token with the upload_accept parameter.

public String generateToken(Id recordID) {
  sharinpix.Client clientInstance = sharinpix.Client.getInstance();
  String token = clientInstance.token(
      new Map<String, Object> {
          'Id' => recordID,          
          'upload_accept' => new List <String> { '.png', '.jpeg' },
          'path' => '/pagelayout/' + recordID,
          'abilities' => new Map<String, Object> {
              recordID => new Map<String, Object> {
                  'Access' => new Map<String, Boolean> {
                      'see' => true,
                      'image_list' => true,
                      'image_upload' => true
                  }
              }
          }
      }
  );
  return token;
}
Click to copy

Tip:

For more information on the common uses of online tokens and how they can be generated, refer to this article: Online token generation methods

0 Comments

Add your comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.