title: Accessing AWS S3 Signed URL via Node js Express
body: <p>I am trying to access the AWS S3 signed URL using a wrapper API created in Node JS and Express.</p>
  
  <p>I am redirecting an url to call the Node API using nginx. In Node API I am setting the 'Content-Type' response headers according to the file type being returned by S3 URL before returning the repsonse from Node API. </p>
  
  <p>When I access the URL to fetch the document in S3 via wrapper Node API I am not getting any content. In case of PDF files I am getting blank white screen.</p>
  
  <p>Below is the block of code I am using to fetch the document from S3 in Node wrapper API and relay the same response.</p>
  
  <pre><code>const request = require('request');
  
  request(s3SignedURL, function (error, result, body) {
      if (!error) {
          res.header('Content-Type','application/pdf');
          res.end(body);
      } else {
          res.status(500).send(error);
      }
  });
  </code></pre>
  
  <p>[EDIT]</p>
  
  <p>I am storing the details of file uploaded S3 in an table and using that table to fetch the document when someone tries to access it. Below is the complete code used.</p>
  
  <pre><code>const S3 = new AWS.S3();
  
  app.get("/getFile/*", function (req, res) {
      var urlInfo = req.url;
      var urlInfoList = urlInfo.split("/");
      var accessCode = urlInfoList[2];
      var accessID = urlInfoList[3];
  
      if (!!accessID &amp;&amp; !!accessCode) {
          db.getFileInfo(accessCode, accessID).then(function (fileInfo) {
              if (fileInfo.length &gt; 0) {
                  var S3Options = {
                      Bucket: Bucketname,
                      Key: fileInfo[0].fileS3Key,
                  };
                  S3.getObject(S3Options, function (err, data) {
                      res.attachment(fileInfo[0].fileS3Key);
                      res.send(data.Body);
                  });
  
                  // request(fileInfo[0].fileS3URL).pipe(res.set('Content-Type', 'application/pdf').set('Content-Disposition', 'inline'));
              } else {
                  res.status(404).send("&lt;html&gt;&lt;head&gt;&lt;title&gt;404 Not Found&lt;/title&gt;&lt;/head&gt;&lt;body bgcolor=\"white\"&gt;&lt;center&gt;&lt;h1&gt;404 Not Found&lt;/h1&gt;&lt;/center&gt;&lt;hr&gt;&lt;/body&gt;&lt;/html&gt;");
              }
          }, function (fileErr) {
              console.log('fileErr');
              console.log(fileErr);
              res.status(404).send("&lt;html&gt;&lt;head&gt;&lt;title&gt;404 Not Found&lt;/title&gt;&lt;/head&gt;&lt;body bgcolor=\"white\"&gt;&lt;center&gt;&lt;h1&gt;404 Not Found&lt;/h1&gt;&lt;/center&gt;&lt;hr&gt;&lt;/body&gt;&lt;/html&gt;");
          });
      } else {
          res.status(404).send("&lt;html&gt;&lt;head&gt;&lt;title&gt;404 Not Found&lt;/title&gt;&lt;/head&gt;&lt;body bgcolor=\"white\"&gt;&lt;center&gt;&lt;h1&gt;404 Not Found&lt;/h1&gt;&lt;/center&gt;&lt;hr&gt;&lt;/body&gt;&lt;/html&gt;");
      }
  });
  </code></pre>
  
  <p>Any help in this regard will be very useful.</p>