Updates
Latest Tweet
What's New?
Check out for latest innovation, a computer based training video collection
Like this Page
Programming Amazon Web Services
PreviewsAmazon Readr |
Share this Great Computer eBookLink to this page |
Our CollectionPrevNext |
|
With this book you will learn all the technical details you need to: Store and retrieve any amount of data using application servers, unlimited data storage, and bandwidth with S3 service Buy computing time using Amazon EC2 Amazon interface to engine demand, load them with the environment application, set permissions, and run your image using as many or few systems are web-scale infrastructure needed Use Amazon's message to store messages as they travel between computers with Amazon SQS Leverage the Amazon FPS service to structure payment instructions and allow the movement of money between two entities, humans or computers Create and store multiple data sets, query your data easily, and return the results using Amazon SimpleDB. Create HTML POST Forms That Allow Your Web Site Visitors to Upload Files Into Your S3 Account Using a Standard Web Browser By James Murty, creator of the Java library JetS3t and author S3 Amazon Web Services Programming Amazon's Wikipedia? Storage Service (S3) provides cheap and unlimited online data storage for anyone with a credit card and Amazon Web Services (AWS) account. You can include these shapes in any web page that allows your web site visitors to send files using nothing more than a standard web browser. in the example below I will use a bucket named s3-bucket. POST Form Web Page Here is a web page with S3 POST Form that you can use as a template for forming your own: S3 POST form file to upload to S3: This template shows several important features of S3 POST form, and web pages that contain it: Web page that contains a form has a meta tag in the head section that tells the web browser to use UTF-8 encoding of unicode characters. This form contains a number of input fields with parameter names and values that will be sent to the S3 service. If there is a required input field is missing, or if the field has a value that is not true, this service will not accept uploads from a form. S3 service uses information from a form? S input field to authorize uploads, and to set the properties object file uploaded. This name can be set before if you know what information the user will upload, for example: upload / monthly_report.txt. If you do not know the name of the file the user will upload, key value can include the special variable $ {filename} which will be replaced with the name of the file upload. For example, the key value uploads / $ {filename} will become the object name uploads / Birthday Cake.jpg if a user uploads a file named Cake.jpg Birthday. S3 will add bucket, key and etag parameters to this URL value to inform your web application from the location and hash value of file upload. Policy A Base64-encoded policy document that applies rules to upload a file sent by the S3 POST form. If you do not know what kind of files the user will upload, you can ask users to provide the appropriate content type, or write browser scripting code that will automatically adjust this value based on file names?. If you do not specify the type of content with this field, S3 will use the default value of application / octet-stream which can prevent some of the web browser capable of displaying the file correctly. File input field that allows the user to select files to upload. At least, you'll need to edit the form action parameter to point to your own S3 bucket?, And set the field value AWSAccessKeyId to your AWS Access Key credential. To complete the form and make it acceptable to the S3 service, you also will need to produce a policy document and signature value. Policy Documents S3 POST form includes the policy document which authorizes the form and provide limits on the file can be uploaded. When S3 receives a file via a form POST, it will check the policy document and signature to confirm that the form was created by someone who is allowed to store files in the target S3 account. A policy document is a collection of properties expressed in JavaScript Object Notation, which means that document? Structure and content must comply with certain formats. conditions - A set of rules to determine the values that may be included in the form of s inputs, and apply the size limit for uploaded files?. This policy has an expiry date January 1, 2009: {"Expires": "2009-01-01T00: 00:00 Z", "conditions": [{"bucket": "s3-bucket"}, ["starts-with", "$ key", "upload / "], {" acl ":" person "}, {" success_action_redirect ":" http://localhost/ "}, [" starts-with "," $ Content-Type "," "], [" content-length-range ", 0, 1048576]]} To make a valid S3 POST, you must include a policy document whose conditions section berisiaturan for almost every input field in forms. At least, this document must include rules for the bucket and key values from the object file uploaded. In addition to the two rules, you will need to include rules for every other input field in the form except for AWSAccessKeyId, signature policies, and files. Because our templates POST form includes the input fields acl, success_action_redirect, and Content-Type, our policy document includes rules corresponding to this field. This policy document also includes the rules item extra-long-range limit the size of files that can be uploaded. There are three kinds of rules you can apply in your policy document: Equality rules, which checks that the input field value? Tuned to a given string. In a policy document on the above, we use starts-with rules for the key and Content-Type fields because we do not know in advance the name of the file, the user will upload, or what type of file you want. If this rule is not included in the policy document, users will be able to upload files of any size up to 5GB limit imposed by S3. Above policy document including content length rule that will prevent the form from uploading files larger than 1MB in size (1,048,576 bytes). If there is any difference between the input fields in forms and values that rule in your policy document, or if your form contains input fields that do not have the appropriate rules in your policy, S3 service will reject the form and returns an XML error message to be understood your users. Sign Your S3 POST Form To complete your S3 POST form, you must sign to prove to the S3 that you actually create a form. If you do not sign the form correctly, or if someone else tries to modify your form after it has been signed, the service will be unable to authorize and will reject the upload. To sign your form, you need to do two steps: Base64-encode the policy document, and put it in shape? Medan policy input. Here are some examples of code fragments to do the job with different languages, assuming you've defined variables and aws_secret_key policy_document. Ruby require 'base64' require 'openssl' require 'digest/sha1' policy = Base64.encode64 (policy_document) gsub ("n ","") signature = Base64.encode64 (OpenSSL:.: HMAC.digest (OpenSSL:: Digest:: Digest.new ('sha1'), aws_secret_key, policy)) gsub ("n ","") import Java sun.misc.BASE64Encoder; javax.crypto.Mac imports; javax.crypto.spec.SecretKeySpec imports; . String policy = (new BASE64Encoder ()) encode (policy_document.getBytes ("UTF-8")) replaceAll ("n ",""); Mac HMAC = Mac.getInstance (" HmacSHA1 ");.. hmac.init (new SecretKeySpec (aws_secret_key.getBytes ("UTF-8"), "HmacSHA1")); String signature = (new BASE64Encoder ()) encode (hmac.doFinal (policy.getBytes ("UTF-8") )) .. replaceAll ("N", ""); Python import base64 import HMAC, policies sha = base64.b64encode (policy_document) signature = base64.b64encode (. Hmac.new (aws_secret_key, policies, sha) digest ()) Once you have calculated the value for input field and a signature policy and included these values in your form, the form must be complete. Save web pages and the form of a document as a file. Html, open in your favorite web browser, and test it by uploading some files to your S3 bucket. Conclusion Forms web page and policy document templates in this article will give you a starting point for creating your own upload forms. With some minor modifications to the document templates and a little coding, you will be able to create basic shapes that make it easy for your web site visitors to upload files to your S3 account. S3 service? S support POST is a powerful feature to use a lot of potential. You can create an upload form to allow your friends and colleagues to send files that are too large to email, or you can modify your web applications to generate forms on-demand so your users can store their data on S3 is not on your own server.
Computer eBook Details
- ISBN-10: 0596515812
- ISBN-13: 9780596515812
- Publisher: O'Reilly
- Pages: 608
- Date: March 2008