Downloading files from NAVER CLOUD PLATFORM Object Storage

Home > NAVER CLOUD PLATFORM Object Storage > Example 03

Explanation

This is an example of downloading a file from NAVER CLOUD PLATFORM Object Storage. If the file stored in Object Storage does not have 'Public-Read' permissions, a credentialing process may be required, so the 'Region/Bucket/ExecSec/SecretExecSec' information is required.

// Set the NCPOS method.
dx.setDownloadMode("NCPOS");
dx.setNCPOSDownloadConfig({
	type: "NON-SECRET",
	accessKeyId: "ABCD...1234",
	secretAccessKey: "ABCD...1234",
	region: "",
	bucket: "abc-bucket"
});

Objects (files) stored in Object Storage buckets can be accessed with the following addressing scheme

https://{region}.object.ncloudstorage.com/{bucket-name}/{key}
https://{bucket-name}.{region}.object.ncloudstorage.com/{key}

Therefore, to download the object, we need to set the object address to the URL of the virtual file.

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%20%28empty%29%20195779.jpg" });

Buckets in Object Storage also need to be set up for downloading. CORS setup is required to communicate between different sources. DEXTUploadX5 uses the takeover feature, so you must add the Accet-Ranges response header.

# NAVER CLOUD PLATFORM Object Storage CORS configuration
{
	"CORSRules": [
	    {
	        "AllowedHeaders": ["*"],
	        "AllowedMethods": ["HEAD", "GET", "PUT", "POST"],
	        "AllowedOrigins": ["*"],
	        "ExposeHeaders": ["ETag", "Accept-Ranges"],
	        "MaxAgeSeconds": 3000	        
	    }
	]
}

Example

Singe-file download

Multiple-files download

To test, you need to set ACCESS_KEY, SECRET_KEY, REGION, and BUCKET_NAME in the script.