NCP Object Storage file download
DEXTUploadX5 provides the ability to download files that exist in NCP Object Storage buckets.
To download files from an NCP Object Storage bucket using DEXTUploadX5, you need to set up CORS to allow different sources to communicate with each other. You must allow the HEAD, GET request methods and the “Accept-Ranges” response header, and be careful not to set the AllowedOrigins property to the value '*' at production time.
# NCP Object Storage CORS configuration
[
{
"AllowedHeaders": ["*"],
"AllowedMethods": ["HEAD", "GET", "PUT", "POST", "DELETE"],
"AllowedOrigins": ["*"]
"ExposeHeaders": ["ETag", "Accept-Ranges"]
}
]
- If files stored in NCP Object Storage 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 NCP Object Storage bucket in the url attribute.
The objects (files) stored in the NCP Object Storage bucket can be accessed with the following addressing scheme
https://{region}.object.ncloudstorage.com/{bucketname}/{key} or https://{bucketname}.{region}.object.ncloudstorage.com/{key}dx.addVirtualFile({ name: "bridge_509147.jpg", size: 509147, url: "https://kr.object.ncloudstorage.com/abc-bucket/bridge_509147.jpg" }); dx.addVirtualFile({ name: "beach_239826.jpg", size: 239826, url: "https://kr.object.ncloudstorage.com/abc-bucket/beach_239826.jpg" }); dx.addVirtualFile({ name: "cosmos (empty) 195779.jpg", size: 195779, url: "https://kr.object.ncloudstorage.com/abc-bucket/cosmos+%28empty%29+195779.jpg" }); - 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 NCP Object Storage bucket, we need to set the download mode using the setDownloadMode method.
// Set it the NCPOS way. dx.setDownloadMode("NCPOS"); dx.setNCPOSDownloadConfig({ type: "NON-SECRET", accessKeyId: "ABCD...1234", secretAccessKey: "ABCD...1234", // kr, us, sg, jp, de region: "kr", 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://kr.object.ncloudstorage.com/abc-bucket/bridge_509147.jpg" }); dx.addVirtualFile({ name: "beach_239826.jpg", size: 239826, url: "https://kr.object.ncloudstorage.com/abc-bucket/beach_239826.jpg" }); dx.addVirtualFile({ name: "cosmos (empty) 195779.jpg", size: 195779, url: "https://kr.object.ncloudstorage.com/abc-bucket/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.setNCPOSDownloadConfig({ ... // 키: 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("NCPOS"); dx.setNCPOSDownloadConfig({ //type: "SECRET", signedURL: "https://domain/path/ncpos-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 environment, 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>NCP Object Storage</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:NCP Object Storage:2.x.x'
-
- 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 NCP Object Storage, the progress shown in the progress window may not be as natural as other download methods.