# Read S3 bucket private pdf file by checking S3 access key and secret key using PDF.js Express

**URL:** <https://pdfjs.community/t/read-s3-bucket-private-pdf-file-by-checking-s3-access-key-and-secret-key-using-pdf-js-express/151>\
**Category:** Technical Support\
**Created:** [July 24, 2020, 4:39pm UTC](https://pdfjs.community/t/read-s3-bucket-private-pdf-file-by-checking-s3-access-key-and-secret-key-using-pdf-js-express/151 "2020-07-24T16:39:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shahkartikk](https://avatars.discourse-cdn.com/v4/letter/s/5fc32e/32.png) [@shahkartikk](https://pdfjs.community/u/shahkartikk)\
**Post date:** [July 24, 2020, 4:39pm UTC](https://pdfjs.community/t/read-s3-bucket-private-pdf-file-by-checking-s3-access-key-and-secret-key-using-pdf-js-express/151/1 "2020-07-24T16:39:24Z")

</div>

Hi,  
As per our earlier discussion to load the document viewer with S3 credentials, I tried with below code:

```javascript
WebViewer({
        path: '/lib/PDFJSExpress/lib',
      }, document.getElementById('viewer1')
    ).then(async instance => {
      const s3 = new AWS.S3();
      const body: BlobPart = await new Promise(resolve => {
      s3.getObject({
        Bucket: 'YOUR_BUCKET',
        Key:'KEY_OF_FILE',
     }, (err, resp) => {
      if (err) {
        console.log(err)
      }
      resolve(resp.Body as BlobPart)
    })
  });
  const file = new Blob([body], {type: 'application/pdf' });
 instance.loadDocument(file);
});

```

I am getting error "Missing Assignment to constant “body” on below line:  
“const body: BlobPart = await new Promise”

Please suggest if required any changes and I am also not getting relevant help from “[https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html)”

Warm Regards,  
Kartik Shah

---

<div class="post-metadata">

**Author:** ![Logan](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/logan/32/13_2.png) [@Logan](https://pdfjs.community/u/Logan)\
**Post date:** [July 24, 2020, 5:13pm UTC](https://pdfjs.community/t/read-s3-bucket-private-pdf-file-by-checking-s3-access-key-and-secret-key-using-pdf-js-express/151/2 "2020-07-24T17:13:49Z")

</div>

Hi!

Are you in a typescript environment? If not you need to remove the Typescript syntax from that code snippet you sent, so it should look like this:

```javascript
WebViewer(
  {
    path: '/lib/PDFJSExpress/lib',
  },
  document.getElementById('viewer1'),
).then(async (instance) => {
  const s3 = new AWS.S3();
  
  const body = await new Promise((resolve) => {
    s3.getObject(
      {
        Bucket: 'YOUR_BUCKET',
        Key: 'KEY_OF_FILE',
      },
      (err, resp) => {
        if (err) {
          console.log(err);
        }
        resolve(resp.Body);
      },
    );
  });

  const file = new Blob([body], { type: 'application/pdf' });
  instance.loadDocument(file);
});

```

If you _are_ using Typescript, then i’m not sure what the issue would be. My best guess would be that your promise is resolving to null or undefined which would make `body` null, and then you are trying to construct a blob with a `null` blob part.

Since this question is not related to PDF.js Express, I am going to close this discussion.

Thanks!  
Logan

---

<div class="post-metadata">

**Author:** ![Logan](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/logan/32/13_2.png) [@Logan](https://pdfjs.community/u/Logan)\
**Post date:** [July 24, 2020, 5:13pm UTC](https://pdfjs.community/t/read-s3-bucket-private-pdf-file-by-checking-s3-access-key-and-secret-key-using-pdf-js-express/151/3 "2020-07-24T17:13:54Z")

</div>


