403响应-s3 PresignedURL

问题描述

我正在Heroku服务器上运行一个应用程序,并尝试使用presignedURL上传到S3。我返回了signurl,但是当我使用它上传文件时,我得到的响应是403。我在某处看到我的签名版本可能不正确,但尚未找到解决方案。我将在下面附加我的源代码

Server side. presign request

客户端上传代码

getSignedRequest(file){
        var that = this
      const xhr = new XMLHttpRequest();
      xhr.open('GET',`/sign-s3?file-name=${encodeURIComponent(file.name)}&file-type=${encodeURIComponent(file.type)}`);
      xhr.onreadystatechange = () => {
        if(xhr.readyState === 4){
          if(xhr.status === 200){
            const response = JSON.parse(xhr.responseText);
            that.uploadFile(file,response.signedRequest,response.url);
          }
          else{
            alert('Could not get signed URL.');
          }
        }
      };
      xhr.send();
    }
    uploadFile(file,signedRequest,url){
      const xhr = new XMLHttpRequest();
      xhr.open('PUT',signedRequest);
      xhr.onreadystatechange = () => {
        console.log()
        if(xhr.readyState === 4){
          if(xhr.status === 200){
            alert('yay')
          }
          else{
            alert('Could not upload file.');
          }
        }
      };
      xhr.send(file);
    }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)