下载s3对象时避免打开新窗口

时间:2018-10-28 04:03:52

标签: reactjs amazon-s3

download code

import React, { PureComponent } from "react";
import FaDownload from "react-icons/lib/fa/download";
import { Auth, API, Storage } from "aws-amplify";


class DownloadCell extends PureComponent {
  onclick = async event => {
    event.preventDefault();
    try {
      const stored = await Storage.get(this.props.node.data.Key.split('/')[1])
      window.open(stored)

    } catch (error) {      
      console.error("S3 download error: ", error);
    }
  };

尝试使用AWS Amplify下载s3存储桶文件,不确定如何正确实现它,因此该文件不会在新窗口中显示。

1 个答案:

答案 0 :(得分:0)

只需移除window.open()

onclick = async event => {
    event.preventDefault();
    try {
      const stored = await Storage.get(this.props.node.data.Key.split('/')[1])
      //whatever you want with the stored
      //.....

    } catch (error) {      
      console.error("S3 download error: ", error);
    }