Uploading files to Amazon S3 (secured)

Home > Amazon S3 > Example 02

Explanation

This is an example of uploading a file to Amazon S3. To upload files to S3, you need to know the region, bucket, access key, and secret access key. However, it is dangerous to use information such as "AccessKey/SecretAccessKey" in public because it should not be exposed to the outside world. To upload without exposing your AWS credentials, you can create a pre-signed address on the backend and use that address to upload files. The signed address is only valid for a certain amount of time and implicitly authorizes the upload. The following code shows how to set up this information

// Set up the AWSS3 method			
dx.setUploadMode("AWSS3");
// Set the type attribute of the settings object to "SECRET" or omit it.
dx.setAWSS3UploadConfig({
    //type: "SECRET",
    initURL: dx5.canonicalize("../service/awss3-upload-helper.ashx?step=0"),
    signedURL: dx5.canonicalize("../service/awss3-upload-helper.ashx?step=1"),
    completeURL: dx5.canonicalize("../service/awss3-upload-helper.ashx?step=2")
});

The three backend addresses are responsible for generating and returning the signed addresses required for each step of the file upload. To return the signed addresses from the backend, we need to use the SDK provided by AWS, which can be installed via NuGet for ASP.NET. In our sample project, we put the required AWS SDK binary files in the packages folder.

For details on generating signed addresses using the AWS SDK, see the awss3-upload-helper.ashx generic handler.

Example

Result