Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
Amudha
Contributor II
Contributor II

S3 Bucket

Hi I am using the below code in Qliksense mash for access qliksense mashup  getting below error while reloading the app

has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>S3 File Downloader</title>
</head>
<body>
 
<label for="file-list">Select File to Download:</label>
<select id="file-list"></select>
<button onclick="downloadS3File()">Download S3 File</button>
 
<script>
function myFunction() {
  // Initialize AWS SDK
  AWS.config.update({
    accessKeyId: 'Key',
    secretAccessKey: '',
    region: ''
  });
 
  const s3 = new AWS.S3();
 
  // Fetch file list from S3 and populate dropdown
  s3.listObjectsV2({ Bucket: 'Bucketname' }, (err, data) => {
    if (err) {
      console.error(err);
    } else {
      const fileList = document.getElementById('file-list');
      data.Contents.forEach(file => {
        const option = document.createElement('option');
        option.value = file.Key;
        option.textContent = file.Key;
        fileList.appendChild(option);
      });
    }
  });
 
  // Function to download S3 file dynamically
  function downloadS3File() {
    const selectedFile = document.getElementById('file-list').value;
 
    if (!selectedFile) {
      console.error('Please select a file to download.');
      return;
    }
 
    const params = {
      Bucket: 'Bucket-Name',
      Key: selectedFile
    };
 
    s3.getObject(params, (err, data) => {
      if (err) {
        console.error(err);
      } else {
        const blob = new Blob([data.Body], { type: data.ContentType });
        const link = document.createElement('a');
        link.href = URL.createObjectURL(blob);
        link.download = ${selectedFile.split('/').pop()}.xlsx; // Adjust the downloaded file name
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
      }
    });
console.log();
  }
 
</script>
 
</body>
</html>
Labels (1)
1 Reply
anat
Master
Master