AWS amplify Storage.put不喜欢星号吗?

时间:2020-09-05 05:05:26

标签: reactjs amazon-web-services amazon-s3 aws-amplify

有人知道为什么AWS Amplify Storage.put不喜欢星号吗?

文件名可以使用星号-> https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html

但是当我尝试以下操作(示例)时:

import React, { useEffect, useState } from 'react';
import Amplify, { API, Storage } from 'aws-amplify';
import { withAuthenticator, AmplifySignOut, AmplifySignIn, AmplifySignUp } from '@aws-amplify/ui-react';
import { MdSend } from 'react-icons/md';
import awsExports from "./aws-exports";
import './App.css';
Amplify.configure(awsExports);

const App = () => {
  const [name, setName] = useState('')
  const [file, setFile] = useState('')

  const onChange = (e) => {
    var stringName = "andy_2020_something*test_hello*description.mp4";
    e.preventDefault()
    if (e.target.files[0] !== null) {
      setFile(e.target.files[0])
      setName(stringName)
    }
  }

  const onSubmit = (e) => {
    e.preventDefault()
    if (file) {
      Storage.put(name, file, {
        contentType: file.type,
      })}}

return (
    <div className='video-uploader'>
        <form onSubmit={(e) => onSubmit(e)}>
          <p>
            <label className='select-label'>Select video: </label>
          </p>
          <p>
            <input
              className='video-input'
              type='file'
              id='file-input'
              accept='image/*, video/*'
              onChange={(e) => onChange(e)}
            />
          </p>
          <button type='submit' className='btn'>
            Submit <MdSend className='btn-icon' />
          </button>
        </form>
      </div>)}

export default withAuthenticator(App)

我得到一个403的回复:

SignatureDoesNotMatch我们计算出的请求签名与您提供的签名不匹配。检查您的密钥和签名方法。

(响应包含更多,但大多数看起来似乎不太有用)。文件名的编码可能是:andy_2020_something%2atest_hello%2adescription.mp4

但是,如果我从文件名中删除星号,则请求将成功。

谢谢!

0 个答案:

没有答案