Amazon S3 file download
DEXTUploadX5 provides the ability to download files that exist in Amazon S3 buckets.
- If files stored in S3 have 'Public-Read' permissions
-
No credentials are required to download files with 'Public-Read' permissions, so you can use DEXTUploadX5's single file download or multiple file download feature to download files. When registering a virtual file, you can set the URL of the file object in the S3 bucket in the url attribute.
The objects (files) stored in the S3 bucket can be accessed with the following addressing scheme
https://{bucketname}.s3.s3.{region}.amazonaws.com/{key}dx.addVirtualFile({ name: "bridge_509147.jpg", size: 509147, url: "https://abc-bucket.s3.ap-northeast-2.amazonaws.com/bridge_509147.jpg" }); dx.addVirtualFile({ name: "beach_239826.jpg", size: 239826, url: "https://abc-bucket.s3.ap-northeast-2.amazonaws.com/beach_239826.jpg" }); dx.addVirtualFile({ name: "cosmos (empty) 195779.jpg", size: 195779, url: "https://abc-bucket.s3.ap-northeast-2.amazonaws.com/cosmos+%28empty%29+195779.jpg" });We also need to set up the S3 bucket for downloading. CORS configuration is required to allow different sources to communicate with each other and must allow the HEAD, GET request method, and the “Accept-Ranges” response header. At production time, be careful not to set the AllowedOrigins property to a value of '*'.
# S3 CORS configuration [ { "AllowedHeaders": ["*"], "AllowedMethods": ["HEAD", "GET", "PUT", "POST", "DELETE"], "AllowedOrigins": ["*"] "ExposeHeaders": ["ETag", "Accept-Ranges"] } ] - Downloading using DEXTUploadX5 and the Browser AWS SDK
-
This method uses the AWS SDK to download a file that exists in a bucket directly from a browser, and requires the following information: region, bucket, accesskey, secret accesskey. And since we need to know that the target exists in an S3 bucket, we need to set the download mode using the setDownloadMode method.
// Set it the AWSS3 way. dx.setDownloadMode("AWSS3"); dx.setAWSS3DownloadConfig({ type: "NON-SECRET", accessKeyId: "ABCD...1234", secretAccessKey: "ABCD...1234", region: "ap-northeast-2", bucket: "abc-bucket" });If you set the address of the object to download to the URL of a virtual file, it will separate the key value from the address to perform the download operation.
dx.addVirtualFile({ name: "bridge_509147.jpg", size: 509147, url: "https://abc-bucket.s3.ap-northeast-2.amazonaws.com/bridge_509147.jpg" }); dx.addVirtualFile({ name: "beach_239826.jpg", size: 239826, url: "https://abc-bucket.s3.ap-northeast-2.amazonaws.com/beach_239826.jpg" }); dx.addVirtualFile({ name: "cosmos (empty) 195779.jpg", size: 195779, url: "https://abc-bucket.s3.ap-northeast-2.amazonaws.com/cosmos+%28empty%29+195779.jpg" });When downloading files using the AWS SDK, you don't necessarily need to specify the address of the object in the url attribute. DEXTUploadX5 will not perform the download if the url property is empty, so you only need to set the minimum amount of information in the url property. However, if you do this, you will not be able to extract the key value from the URL, so you will need to set a function to generate the key in the makeKey property.
dx.setAWSS3DownloadConfig({ ... // 키: componentname/filename makeKey: item => `${item.controlId}/${item.name}` });You can then download the file using a button binding or by calling the download method directly, just as you would for a single file download or a multi-file download.
- Downloading using a Presigned URL
-
It's dangerous to use information like “access key, secret passphrase” in a public place because it shouldn't be exposed to the outside world. To download without exposing your AWS credentials, you can generate a pre-signed address on the backend and use that address to download the file.
dx.setDownloadMode("AWSS3"); dx.setAWSS3DownloadConfig({ //type: "SECRET", signedURL: "https://domain/path/awss3-download-geturl" });The backend address specified by the signedURL property is responsible for generating and returning the signed address needed to download the file. To return a signed address on the backend, you must use an SDK provided by AWS. By generating a pre-signed address on the server side using the appropriate AWS SDK for your platform, you can let DEXTUploadX5 handle the file download process without exposing information such as credentials.
JExamples are provided for Java Web Application and ASP.NET environments, so please refer to the provided examples for implementation.
-
How to get the AWS SDK for Java and Maven environments
<dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>s3</artifactId> <version>2.x.x</version> </dependency> -
How to get the AWS SDK if your environment is using Java and Gradle
implementation 'software.amazon.awssdk:s3:2.x.x'
-
To get the AWS SDK if you are in an ASP.NET environment
Install the AWSSDK.S3 package using the NuGet package manager, and you will get AWSSDK.Core.dll and AWSSDK.S3.dll.
-
- Features
-
- Supports takeover functionality.
- When using the browser AWS SDK, there may be additional time to download the SDK when you start downloading files.
- When downloading from S3, the progress shown in the progress window may not be as natural as other download methods.