Uploading files to NAVER CLOUD PLATFORM Object Storage

Home > NAVER CLOUD PLATFORM Object Storage > Example 01

Explanation

This is an example of uploading a file to NAVER CLOUD PLATFORM Object Storage. To upload a file to Object Storage, you need to know the region/bucket/exec/secret executable information in advance. The following code shows how to set this information.

// Set the NCPOS method.
dx.setUploadMode("NCPOS");
// Set the type property of the configuration object to “NON-SECRET”, then set the rest of the values.
dx.setNCPOSUploadConfig({
    type: "NON-SECRET",
	accessKeyId: "ABCD...1234",
	secretAccessKey: "ABCD...1234",
	region: "",
	bucket: "abc-bucket"
});

The example uses the filename as the key. If you want to set the key manually, you can set a function to generate the key in the makeKey property of the configuration object.

dx.setNCPOSUploadConfig({
    ...
	//  key: component-name/filename  
    makeKey: item => `${item.controlId}/${item.name}`
});

The bucket in Object Storage also needs to be set up for uploads. CORS setup is required to allow different sources to communicate with each other. DEXTUploadX5 uses a multipart upload method to upload to the bucket, so you must allow the PUT request method and ETag response header.

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

Example

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

Result