Encrypt File
2 0
Read Time:1 Minute, 40 Second

During the last post we discussed DIRECTORY table and GET_PRESIGNED_URL two key properties in snowflake. We used these features to download the File Snowflake WEBUI instead of respective cloud provider UI framework. We accessed the file present on the external stage i.e. AWS using DIRECTORY and GET_PRESIGNED_URL in SQL query. Now in addition to it we want to download the files present into the Snowflake Internal stage area. At first glance the requirement seems straightforward and we can use the same query (only change Internal stage name).

We have placed one file to the snowflake internal staging area.

list @internalstage

Internal Stage

We have downloaded the file using GET_PRESIGNED_URL and verify the content of file. Please note, There is one limitation while loading the data from Internal stage. We can able to down load the file but the content of files are encrypted.

Encrypt File

This is the expected outcome because while using PUT command snowflake use the internal key to decrypt the content of file. GET command uses the same Key to encrypt the file. In case of Presigned URL we are able to download the file from internal stage which is encrypted by PUT command. However no where we used GET command and hence we see encrypted data in file.

If files downloaded from an internal stage are corrupted, verify with the stage creator that

ENCRYPTION = (TYPE = ‘SNOWFLAKE_SSE’) is set for the stage

create or replace stage internalstage
directory = (enable = true)
file_format = dir_format
ENCRYPTION = (TYPE = 'SNOWFLAKE_SSE')

alter stage internalstage refresh;

SELECT
get_presigned_url(@internalstage, 'Customer_Invoice.csv') as presigned_url FROM DIRECTORY( @internalstage );

Presigned_Internal

Copy the URL and paste in the browser:

It will start downloading the file on your local drive.

File download


Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

Leave a Reply

Your email address will not be published. Required fields are marked *