> For the complete documentation index, see [llms.txt](https://bayun.gitbook.io/bayun-awss3-wrapper-javascript-programming-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bayun.gitbook.io/bayun-awss3-wrapper-javascript-programming-guide/5.-store-and-retrieve-files-securely-from-amazon-s3/5.2-transferring-files-using-secures3.md).

# 5.2 Transferring files using SecureS3

### 5.2.1 Initialize the SecureS3 object

{% tabs %}
{% tab title="JavaScript" %}

```javascript
var secureS3 = new SecureS3(
        "<bayunSessionId>",  // bayun sessionId will be returned when user successfully able to signIn.
        "<apiVersion>",  // provided on AWS console
        "<accessKeyId>", // provided on AWS console
        "<secretAccessKey>", // provided on AWS console
        "<signatureVersion>", // provided on AWS console
        "<region>", // provided on AWS console
        "<bucket>", // provided on AWS console
);

//set EncryptionPolicy and keyGenerationPolicy by these methods which are going
//to be used while locking/encrypting a file before uploading to s3.
secureS3.setEncryptionPolicy(BayunCore.EncryptionPolicy.EMPLOYEE);
secureS3.setKeyGenerationPolicy(BayunCore.KeyGenerationPolicy.ENVELOPE);
    
```

{% endtab %}
{% endtabs %}

### 5.2.2 Upload a File to Amazon S3 using secureS3 object

{% tabs %}
{% tab title="JavaScript" %}

```javascript
var file = "<fileToBeUpload>" //document.getElementById("file").files[0];
await secureS3.upload(file);
```

{% endtab %}
{% endtabs %}

### 5.2.3 Download a File from Amazon S3 using secureS3 object

{% tabs %}
{% tab title="JavaScript" %}

```javascript
await secureS3.downloadFile("<yourFileName.extension>"); // we can get uploaded filename from AWS buckets console
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
By doing the above, all data written to S3 is automatically locked before upload and unlocked after download in such a manner that nobody other than the customer (and especially the developer) has access to any of the encryption keys or the data itself.
{% endhint %}
