如何在图像上传到s3存储桶之前重命名图像?

时间:2016-11-14 10:00:34

标签: javascript amazon-web-services amazon-s3

我希望在上传到s3 Bucket之前重命名该图像以避免重复图像(s3将用旧的替换新图像,如果有任何相同的文件要上传)在javaScript中

<!DOCTYPE html>
<html>

<body>

  A FileUpload object:
  <input type="file" id="upload" name="filename">

  <p>Click the buttons below to display and/or change the value of the name attribute of the file button above.</p>

  <button onclick="display()">Display name</button>
  <button onclick="change()">Change name</button>

  <script>
    function display() {
      var fullPath = document.getElementById('upload').value;
      if (fullPath) {
        var startIndex = (fullPath.indexOf('\\') >= 0 ? fullPath.lastIndexOf('\\') : fullPath.lastIndexOf('/'));
        var filename = fullPath.substring(startIndex);
        if (filename.indexOf('\\') === 0 || filename.indexOf('/') === 0) {
          filename = "hello" + filename.substring(1);

        }
        alert(filename);
      }

    }

    function change() {
      var x = document.getElementById("myFile").name = "newFileName";
      alert("The name was changed to: " + x);
    }
  </script>

</body>

</html>

在上面的代码中,它只是设置文件名并尝试附加某些内容(我们想要的是“随机数”)。 但我想将带有新名称的图片上传到s3存储桶

0 个答案:

没有答案