我希望在上传到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存储桶