howto upload a file via a single html form to more than just a single server
Sending a file/key to Amazon S3 via a html form and HTTP Post is quite easy and working.
But I want to send 开发者_开发问答a file to several S3-compatible sites via HTTP POST and a single html form.
How can I do this?
As far as I know, HTTP POST can only be directed at a single target location.
I want the file to be sent to the first S3-compatible site (server) and then to the second one and than to the third one and so on without any need for the user to interact.
Is this possible?
Thanks a lot for any help.
You can use flash to do that for you (a lot easier).
Or I think you can use invisible frames and javascript. Target the upload on the hidden frames and change the action. The example below will upload the same file one server after the other.
Here's the code:
<!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>
This is not possible with plain HTML and a browser.
精彩评论