通过 html 表单和 HTTP Post 将文件/ key 发送到 Amazon S3 非常简单且有效。
但我想通过 HTTP POST 和单个 html 表单将文件发送到多个 S3 兼容站点。
我该怎么做?
据我所知,HTTP POST 只能针对单个目标位置。
我希望将文件发送到第一个 S3 兼容站点(服务器),然后发送到第二个,然后再发送到第三个,依此类推,而无需用户进行任何交互。
这可能吗?
非常感谢您的帮助。
最佳答案
您可以使用 flash 为您做到这一点(容易得多)。
或者我认为您可以使用隐形框架和 javascript。将上传定位到隐藏帧并更改操作。下面的示例将一个服务器一个接一个地上传同一个文件。
代码如下:
<!DOCTYPE html>
<html>
<head>
<title>Sample</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$('#button1').click(function(){
$('#frame1').load(function(){
$('#form1')
.attr('action', 'http://server2/')
.attr('target', 'frame2')
.submit();
});
$('#form1')
.attr('action', 'http://server1/')
.attr('target', 'frame1')
.submit();
return true;
});
});
</script>
<style type="text/css"></style>
</head>
<body>
<form id="form1" method="POST" enctype="multipart/form-data" action="http://cgi-lib.berkeley.edu/ex/fup.cgi">
File to upload: <input type="file" name="upfile" /><br>
Notes about the file: <input type="text" name="note" /><br>
</form>
<button id="button1">Multiple upload</button>
<br />
<iframe id="frame1" name="frame1"></iframe>
<iframe id="frame2" name="frame2"></iframe>
</body>
</html>
关于javascript - 如何通过单个 html 表单将文件上传到多个服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3820916/