JSP S3Upload


Hits: 5289  

JavaScript is good alternative to bypass AWS bucket policies 😉

<%@ include file="config.jsp" %>
<%@page import="java.util.Calendar"%>
<%@page import="java.util.Date"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<title>S3 Upload - JSP Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<script src="sha1.js"></script>
<script src="webtoolkit.base64.js"></script>
<script src="script.js"></script>

<script>

function uploadS3()
{
var awsid = '<%=awsAccessKey %>';
var awskey = '<%=awsSecretKey %>';

var fileField = document.getElementById("file").value;

var policyText = '{"expiration": "2015-01-01T12:00:00.000Z","conditions": [{"bucket": "<%=bucket %>" },{"acl": "<%=acl %>" },["eq", "$key", "'+fileField+'"],["starts-with", "$Content-Type", "text/"],]}'; 

var policyBase64 = Base64.encode(policyText);

var signature = b64_hmac_sha1(awskey, policyBase64);

document.getElementById("policy").value = policyBase64;
document.getElementById("signature").value = signature;
document.getElementById("key").value = fileField;

//document.getElementById("postform").submit();

document.getElementById("result").innerHTML = '<a href="http://s3.amazonaws.com/<%=bucket %>/'+fileField+'">http://s3.amazonaws.com/<%=bucket %>/'+fileField+'</a>'; 

}

</script>

</head><body>

<strong>Uploading to Amazon S3</strong>

<div class="main">

<p>

<form id="postform" action="http://s3.amazonaws.com/<%=bucket %>" method="post" onsubmit="return uploadS3();" enctype="multipart/form-data">
<input type="hidden" name="key" id="key" value="" />
<input type="hidden" name="acl" id="acl" value="<%=acl %>" />
<input type="hidden" name="content-type" id="content-type" value="text/plain" />
<input type="hidden" name="AWSAccessKeyId" id="AWSAccessKeyId" value="<%=awsAccessKey %>" />
<input type="hidden" name="policy" id="policy" value="" />
<input type="hidden" name="signature" id="signature" value="" />
<input name="file" id="file" type="file" />
<input name="submit" value="Upload" type="submit" />
</form>

<div id="result"></div>

</p>
</div>

</body></html>
PHP based S3 Upload Tool: http://svnlabs.com/demo/s3/

You are great if you can find your faults, Greater if you can correct them, But greatest if you accept others with their faults.

Published by

Sandeep Verma

I’m an Entrepreneur. I’m proud to work as Blogger, LAMP Programmer, Linux Admin, Web Consultant, Cloud Manager, Apps Developer, Searcher. Concentrate > Observe > Imagine > Launch

19 thoughts on “JSP S3Upload”

  1. it shows something like this

    PermanentRedirectThe bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.

    plzz help

  2. Pingback: polmed
  3. I am really inspired with your writing skills and also
    with the layout for your blog. Is this a paid theme or did you customize it your self?
    Anyway keep up the nice quality writing, it’s rare to
    peer a great weblog like this one today..

  4. Great article! That is the type of info that are
    meant to be shared across the web. Shame on the seek engines for
    no longer positioning this put up higher! Come on over and visit my
    site . Thanks =)

  5. I’m very happy to uncover this page. I want
    to to thank you for your time due to this wonderful read!!
    I definitely savored every part of it and i also have you book marked to see new
    things in your website.

  6. Hi! This is my first comment here so I just wanted to give a quick shout out and
    tell you I really enjoy reading through your posts.
    Can you recommend any other blogs/websites/forums that cover the same subjects?
    Thanks!

  7. I don’t even know how I ended up here, but I thought this post was great.
    I don’t know who you are but definitely you are going to a famous
    blogger if you aren’t already 😉 Cheers!

  8. I don’t even know the way I finished up right here, however I
    believed this submit was once good. I do not recognise who you might be but definitely you’re going to a well-known blogger when you
    aren’t already. Cheers!

  9. Great post. I used to be checking continuously this blog and I am
    impressed! Very helpful info specially the final section :
    ) I deal with such info a lot. I used to be seeking this particular info for a very
    long time. Thank you and best of luck.

  10. I was more than happy to find this great site. I wanted to thank you for your
    time for this wonderful read!! I definitely enjoyed every bit of
    it and I have you bookmarked to check out new stuff in your site.

  11. Pretty nice post. I simply stumbled upon your blog and wanted to say that I have really loved surfing
    around your blog posts. In any case I’ll be subscribing in your rss feed and I hope you write once more very soon!

Leave a Reply

Your email address will not be published.

*