-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost_sample.html
288 lines (241 loc) · 12.6 KB
/
post_sample.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
test
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>HTML5 uploads to Amazon S3 - interactive demo</title>
<script src="sha1.js"></script>
<script src="webtoolkit.base64.js"></script>
<script src="upload.js"></script>
<script type="text/javascript">
function generatePolicy() {
var awsid = document.getElementById("idAWSAccessKeyId").value;
var awskey = document.getElementById("awskey").value;
var policyText = document.getElementById("policy").value;
var policyBase64 = Base64.encode(policyText);
document.getElementById("gen-policy").value = policyBase64;
var signature = b64_hmac_sha1(awskey, policyBase64);
document.getElementById("gen-signature").value = signature;
}
function applyPolicy() {
var signature = document.getElementById("gen-signature").value;
var policy = document.getElementById("gen-policy").value;
document.getElementById("idsignature").value = signature;
document.getElementById("idpolicy").value = policy;
var bucketJson = eval('('+document.getElementById("policy").value+')');
var bucket = bucketJson.conditions[0].bucket;
document.getElementById("idbucket").value = bucket;
}
function basicSendFile(){
var form = document.getElementById("postform");
var bucket = document.getElementById("idbucket").value;
form.action = "http://s3.amazonaws.com/"+bucket;
form.submit();
}
window.onload = function(){
// create elements
var input = document.getElementById("file");
var info = document.getElementById("ajax-message"),
progress = document.getElementById("progress");
var startUpload = function(){
// disable the input
input.setAttribute.disabled = true;
var handler = {
maxSize: 2024000000,
// list of files to upload
file:input.files[0],
parameters: {
acl: document.getElementById('idacl').value,
aws_access_key: document.getElementById('idAWSAccessKeyId').value,
policy: document.getElementById('idpolicy').value,
signature: document.getElementById('idsignature').value,
url: "http://s3.amazonaws.com/"+document.getElementById('idbucket').value
},
// clear the container
onloadstart:function(){
info.innerHTML = "Init upload ... ";
progress.style.width = "1%";
},
// do something during upload ...
onprogress:function(rpe){
progress.style.width = (rpe.loaded * 100) / rpe.total + "%";
},
// fired when last file has been uploaded
onload:function(rpe, xhr){
var msg = '';
if (xhr.status == 204) {
progress.style.width = "100%";
var link = xhr.getResponseHeader("Location");
msg = "Uploaded successfully: <br/> link: <small><a href='"+link+"'>"+link+"</a></small>";
} else {
msg = "Error. ";
msg += "<i>" + xhr.responseText + "</i>";
}
info.innerHTML = ["", msg ].join("<br />");
// enable the input again
input.removeAttribute("disabled");
},
// if something is wrong ... (from native instance or because of size)
onerror:function(msg){
info.innerHTML = msg;
// enable the input again
input.removeAttribute("disabled");
},
onabort:function(){
info.innerHTML += "Aborted!";
}
};
handler.sent = 0;
handler.total = handler.file.fileSize;
sendFile(handler);
};
document.getElementById('ajax-upload-button').addEventListener("click", startUpload, false);
document.getElementById('basic-upload-button').addEventListener("click", basicSendFile, false);
};
</script>
<style type="text/css">
body{background: #BFCFCC; text-align:center; font-size:12px; caption-side:black;}
input, select, textarea{background: #f9e9c2; border:none; -moz-border-radius: 6px; -webkit-border-radius: 6px; padding:3px;}
input{height:22px;}
#content{width:980px; height:auto; margin:auto;}
.col{min-height:550px; height:auto !important; height:650px; float:left; padding:10px 10px 30px; background: #8C9C9A; margin-left:10px;
-moz-border-radius: 15px; -webkit-border-radius: 15px;}
.col img, .col .step{float:left;}
.row{position:relative; padding:10px; margin:auto;}
.step{width:50px; height:35px; padding-top:15px; -moz-border-radius: 10px; -webkit-border-radius: 10px; background:white; color:orange; text-align:center; font-weight:bold; font-size:13px;
font-family:tahoma;}
.info{ width:93%; padding: 6px; background:#bfcfcf; text-align:left; -moz-border-radius: 5px; -webkit-border-radius: 5px; margin:auto; color:#111;}
.gen-signature{width:95%; margin:30px auto 0 auto;}
textarea#policy{font-size:11px; width:97%; height:130px;}
input#awskey{width:90%;}
input#gen-signature{width:90%;}
#form-table{width:95%; margin-top:30px;}
#form-table tr td input{ width:98%;}
#form-table tr td{padding:0 10px 13px 0; height:auto; font-size:11px; color:black; }
#basic-upload-button, #ajax-upload-button{width:80%; height:35px; margin: 10px 0; background:orange; border:2px solid white;}
#generate, #apply-signature{width:80%; height:35px; background: #485C5A; border:2px solid white; color: white;}
#apply-signature{width:50%;}
.ajax-message-wrapper{width:96%; padding:5px; color: white; text-align:left; border: 1px solid #ccc; color:black;}
#ajax-message{font-size:11px; overflow:auto; padding: 0 0 5px 0; height:135px;}
.progress-wrapper{position:relative; width:100%; height:10px; margin: 10px 0; border:1px solid #ccc; }
#progress{width:1%; background:white; height:100%;}
#ifr{ display:block; width:1px; height:1px; }
</style>
</head>
<body>
<div id="content">
<div class="col" style="width:35%;">
<div class="info">
<h2>step 1</h2>Suspendisse potenti. Phasellus rutrum ante in ante vestibulum et aliquet lectus volutpat. Nam a lorem sit amet felis venenatis dignissim. In sodales turpis sed justo adipiscing vitae condimentum eros varius.
</div>
<div class="gen-signature">
<table cellpadding="0" cellspacing="0" border="0"
<tr>
<td width="60%" align="center">
Policy
<textarea id="policy" cols="40" rows="12">{
"expiration": "2012-01-01T12:00:00.000Z",
"conditions": [
{"bucket": "<bucketname>" },
{"acl": "public-read" },
["starts-with", "$key", ""],
["starts-with", "$Content-Type", ""],
]
}
</textarea>
</td>
<td width="40%" align="center">
AWS Key
<input id="awskey" value="" type="text">
</td>
</tr>
<tr>
<td colspan="2" height="80px"e><input type="button" id="generate" onclick="generatePolicy()" value="Calculate Policy & Signature"></td>
</tr>
<tr>
<td width="50%" align="center">
Policy<br/>
<input value="" name="policy" id="gen-policy" type="text">
</td>
<td width="50%">
Signature<br/>
<input value="" name="signature" id="gen-signature" type="text">
</td>
</tr>
</table>
</div>
<br/>
<br/>
<br/>
<input type="button" id="apply-signature" onclick="applyPolicy()" value="Apply >>">
</div>
<div class="col" style="width:33%;">
<div class="info">
<h2>step 2</h2>Suspendisse potenti. Nam a lorem sit amet felis venenatis dignissim. In sodales turpis sed justo adipiscing vitae condimentum eros varius.
</div>
<table cellpadding="0" cellspacing="0" border="0" id="form-table">
<tr>
<td width="35%" align="right">Bucket name</td>
<td width="65%" align="left"><input value="" name="key" id="idbucket" type="text"></td>
</tr>
</table>
<form action="http:/s3.amazonaws.com" enctype="multipart/form-data" method="post" target="ifr" id="postform">
<table cellpadding="0" cellspacing="0" border="0" id="form-table">
<tr>
<td width="35%" align="right">Key</td>
<td width="65%" align="left"><input value="dummy test-file" name="key" id="idkey" type="text"></td>
</tr>
<tr>
<td width="35%" align="right">ACL</td>
<td width="65%" align="left"><input value="public-read" name="acl" id="idacl" type="text"></td>
</tr>
<tr>
<td width="35%" align="right">Content-type</td>
<td width="65%" align="left"><input value="text/plain" name="content-type" id="idcontent-type" type="text"></td>
</tr>
<tr>
<td width="35%" align="right">AWSAccessKeyId <br /><small>(usually hidden)</small></td>
<td width="65%" align="left"><input value="" name="AWSAccessKeyId" id="idAWSAccessKeyId" type="text"></td>
</tr>
<tr>
<td width="35%" align="right">policy <br /><small>(usually hidden)</small></td>
<td width="65%" align="left"><input value="" name="policy" id="idpolicy" typarameters.policype="text"></td>
</tr>
<tr>
<td width="35%" align="right">signature <br /><small>(usually hidden)</small></td>
<td width="65%" align="left"><input value="" name="signature" id="idsignature" type="text"></td>
</tr>
<tr>
<td width="35%" align="right">File</td>
<td width="65%" align="left" class="file"><input name="file" type="file" id="file"></td>
</tr>
</table>
</form>
</div>
<div class="col" style="width:22%;">
<div class="row" style="border-bottom:1px solid #222; height:310px;">
<div class="info">
<b>Ajax upload</b> nam adipiscing augue at nibh interdum dapibus.
</div>
<input type="button" id="ajax-upload-button" value="Ajax upload" />
<div class="progress-wrapper">
<div id="progress" style="width:1%; height:10px; background:white; "></div>
</div>
<div class="ajax-message-wrapper">
<small><b>messages:</b></small>
<div id="ajax-message"></div>
</div>
</div>
<div class="row" style="height:190px;">
<div class="info">
<b>Basic upload</b> Nulla sit amet ante quam. Sed et risus in dui accumsan sodales eget eget lorem.
</div>
<input type="button" id="basic-upload-button" value="Basic upload" />
<iframe name="ifr" id="ifr" frameborder="0" scrolling="no"></iframe>
</div>
</div>
<div style="clear:both;"></div>
</div>
</body>
</html>