Permalink
Browse files

initial commit

  • Loading branch information...
Zhang Yuanyi
Zhang Yuanyi committed Nov 17, 2008
0 parents commit b3432fb22a4d5fad7d9e0c760c40d6a68a40303e
Showing with 3,171 additions and 0 deletions.
  1. +20 −0 MIT-LICENSE
  2. +13 −0 README
  3. +22 −0 Rakefile
  4. +5 −0 crossdomain.xml
  5. +184 −0 flex/S3SWFUpload.mxml
  6. +196 −0 flex/com/adobe/net/MimeTypeMap.as
  7. +33 −0 flex/com/elctech/S3UploadOptions.as
  8. +228 −0 flex/com/elctech/S3UploadRequest.as
  9. +141 −0 flex/index.template.html
  10. +1 −0 generators/s3_swf_upload/USAGE
  11. +54 −0 generators/s3_swf_upload/lib/insert_routes.rb
  12. +19 −0 generators/s3_swf_upload/s3_swf_upload_generator.rb
  13. +278 −0 generators/s3_swf_upload/templates/AC_OETags.js
  14. BIN generators/s3_swf_upload/templates/S3SWFUpload.swf
  15. +14 −0 generators/s3_swf_upload/templates/amazon_s3.yml
  16. +40 −0 generators/s3_swf_upload/templates/controller.rb
  17. +1 −0 generators/s3_swf_upload/templates/initializer.rb
  18. +33 −0 generators/s3_swf_upload/templates/spec/controllers/s3_signatures_controller_spec.rb
  19. +1 −0 init.rb
  20. +1 −0 install.rb
  21. +12 −0 lib/patch/integer.rb
  22. +4 −0 lib/s3_swf_upload.rb
  23. +21 −0 lib/s3_swf_upload/s3_config.rb
  24. +203 −0 lib/s3_swf_upload/signature.rb
  25. +63 −0 lib/s3_swf_upload/view_helpers.rb
  26. +20 −0 s3_swf_upload/MIT-LICENSE
  27. +13 −0 s3_swf_upload/README
  28. +22 −0 s3_swf_upload/Rakefile
  29. +5 −0 s3_swf_upload/crossdomain.xml
  30. +184 −0 s3_swf_upload/flex/S3SWFUpload.mxml
  31. +196 −0 s3_swf_upload/flex/com/adobe/net/MimeTypeMap.as
  32. +33 −0 s3_swf_upload/flex/com/elctech/S3UploadOptions.as
  33. +228 −0 s3_swf_upload/flex/com/elctech/S3UploadRequest.as
  34. +141 −0 s3_swf_upload/flex/index.template.html
  35. +1 −0 s3_swf_upload/generators/s3_swf_upload/USAGE
  36. +54 −0 s3_swf_upload/generators/s3_swf_upload/lib/insert_routes.rb
  37. +19 −0 s3_swf_upload/generators/s3_swf_upload/s3_swf_upload_generator.rb
  38. +278 −0 s3_swf_upload/generators/s3_swf_upload/templates/AC_OETags.js
  39. BIN s3_swf_upload/generators/s3_swf_upload/templates/S3SWFUpload.swf
  40. +14 −0 s3_swf_upload/generators/s3_swf_upload/templates/amazon_s3.yml
  41. +40 −0 s3_swf_upload/generators/s3_swf_upload/templates/controller.rb
  42. +1 −0 s3_swf_upload/generators/s3_swf_upload/templates/initializer.rb
  43. +33 −0 s3_swf_upload/generators/s3_swf_upload/templates/spec/controllers/s3_signatures_controller_spec.rb
  44. +1 −0 s3_swf_upload/init.rb
  45. +1 −0 s3_swf_upload/install.rb
  46. +12 −0 s3_swf_upload/lib/patch/integer.rb
  47. +4 −0 s3_swf_upload/lib/s3_swf_upload.rb
  48. +21 −0 s3_swf_upload/lib/s3_swf_upload/s3_config.rb
  49. +203 −0 s3_swf_upload/lib/s3_swf_upload/signature.rb
  50. +34 −0 s3_swf_upload/lib/s3_swf_upload/view_helpers.rb
  51. +4 −0 s3_swf_upload/tasks/s3_swf_upload_tasks.rake
  52. +8 −0 s3_swf_upload/test/s3_swf_upload_test.rb
  53. +1 −0 s3_swf_upload/uninstall.rb
  54. +4 −0 tasks/s3_swf_upload_tasks.rake
  55. +8 −0 test/s3_swf_upload_test.rb
  56. +1 −0 uninstall.rb
@@ -0,0 +1,20 @@
+Copyright (c) 2008 [name of plugin creator]
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13 README
@@ -0,0 +1,13 @@
+S3SwfUpload
+===========
+
+Introduction goes here.
+
+
+Example
+=======
+
+Example goes here.
+
+
+Copyright (c) 2008 [name of plugin creator], released under the MIT license
@@ -0,0 +1,22 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the s3_swf_upload plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the s3_swf_upload plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'S3SwfUpload'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
@@ -0,0 +1,5 @@
+<?xml version="1.0"?>
+<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
+<cross-domain-policy>
+ <allow-access-from domain="*" secure="false" />
+</cross-domain-policy>
@@ -0,0 +1,184 @@
+<?xml version="1.0" encoding="utf-8"?>
+<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init();" layout="absolute" height="35" width="300">
+
+ <mx:Script>
+ <![CDATA[
+ import com.elctech.S3UploadRequest;
+
+ import mx.controls.Alert;
+ import flash.external.ExternalInterface;
+ import flash.net.FileReference;
+
+ import com.adobe.net.MimeTypeMap;
+
+ import com.elctech.S3UploadOptions;
+
+ private var mimeMap:MimeTypeMap = new MimeTypeMap();
+ private var options:S3UploadOptions = new S3UploadOptions();
+ private var fileReference:FileReference;
+
+ private function init():void {
+ if (ExternalInterface.available) {
+ ExternalInterface.addCallback("initS3SWFUpload", initS3SWFUpload);
+ ExternalInterface.addCallback("startUpload", upload);
+ ExternalInterface.call("initS3SWFUpload");
+ }
+ }
+
+ private function initS3SWFUpload(AWSAccessKeyId:String, bucket:String, Secure:String, Expires:String, acl:String, SignatureQueryURL:String):void {
+ // TODO: validate
+ this.options.AWSAccessKeyId = AWSAccessKeyId;
+ this.options.bucket = bucket;
+ this.options.Secure = Secure;
+ this.options.Expires = Expires;
+ this.options.acl = acl;
+ this.options.SignatureQueryURL = SignatureQueryURL;
+ this.options.PrefixPath = "";
+ }
+
+ private function browser():void {
+ this.fileReference = new FileReference();
+
+ // setup file reference event handlers
+ fileReference.addEventListener(Event.CANCEL, function(event:Event):void {
+ // TODO: cancel the upload.
+ });
+
+ fileReference.addEventListener(Event.SELECT, function(event:Event):void {
+ // set options.FileName
+ options.FileName = fileReference.name;
+ textInput.text = options.FileName;
+
+ // set options:FileSize
+ options.FileSize = fileReference.size.toString();
+
+ // set options.ContentType
+ var FileNameArray:Array = options.FileName.split(/\./);
+ var FileExtension:String = FileNameArray[FileNameArray.length - 1];
+ options.ContentType = mimeMap.getMimeType(FileExtension);
+
+ ExternalInterface.call("s3SWFFileSelected", options.FileName, options.FileSize);
+ });
+
+ fileReference.browse();
+ }
+
+ private function upload(prefixPath:String = ""):void {
+ var request:URLRequest = new URLRequest(options.SignatureQueryURL);
+ var loader:URLLoader = new URLLoader();
+ var variables:URLVariables = new URLVariables();
+
+ // set options.PrefixPath and options.key
+ options.PrefixPath = prefixPath; // override options.PrefixPath
+ options.key = options.PrefixPath + options.FileName;
+
+ variables.expiration_date = options.Expires;
+ variables.bucket = options.bucket;
+ variables.file_size = options.FileSize;
+ variables.acl = options.acl;
+ variables.content_type = options.ContentType;
+ variables.key = options.key;
+
+ request.method = URLRequestMethod.POST;
+ request.data = variables;
+ loader.dataFormat = URLLoaderDataFormat.TEXT;
+
+ configureListeners(loader);
+ loader.load(request);
+ }
+
+ private function configureListeners(dispatcher:IEventDispatcher):void {
+ dispatcher.addEventListener(Event.COMPLETE, completeHandler);
+ dispatcher.addEventListener(Event.OPEN, openHandler);
+ dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
+ dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
+ dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
+ dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
+ }
+
+ private function completeHandler(event:Event):void {
+ var loader:URLLoader = URLLoader(event.target);
+ var xml:XML = new XML(loader.data);
+ var xmllist:XMLList = xml.children();
+
+ // set options.policy and options.signature
+ for each(var elem:XML in xmllist) {
+ switch(elem.name().toString()) {
+ case 'policy':
+ options.policy = elem.toString();
+ break;
+ case 'signature':
+ options.signature = elem.toString();
+ break;
+ }
+ }
+
+ // post upload file to S3
+ post(options)
+ }
+
+ private function openHandler(event:Event):void {
+ trace("openHandler: " + event);
+ }
+
+ private function progressHandler(event:ProgressEvent):void {
+ trace("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal);
+ }
+
+ private function securityErrorHandler(event:SecurityErrorEvent):void {
+ trace("securityErrorHandler: " + event);
+ }
+
+ private function httpStatusHandler(event:HTTPStatusEvent):void {
+ trace("httpStatusHandler: " + event);
+ }
+
+ private function ioErrorHandler(event:IOErrorEvent):void {
+ trace("ioErrorHandler: " + event);
+ }
+
+ private function post(options:S3UploadOptions):void {
+
+ var request:S3UploadRequest = new S3UploadRequest(options);
+
+ // hook up the user interface
+ request.addEventListener(Event.OPEN, function(event:Event):void {
+ textInput.text = "Uploading...";
+ trace(event);
+ });
+ request.addEventListener(ProgressEvent.PROGRESS, function(event:ProgressEvent):void {
+ // TODO: setProgressBar
+ });
+ request.addEventListener(IOErrorEvent.IO_ERROR, function(event:IOErrorEvent):void {
+ textInput.text = "Upload error!";
+ trace(event);
+ });
+ request.addEventListener(SecurityErrorEvent.SECURITY_ERROR, function(event:SecurityErrorEvent):void {
+ textInput.text = "Upload error!";
+ trace(event);
+ });
+ request.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, function(event:Event):void {
+ textInput.text = "Upload complete!";
+ trace(event);
+
+ // external javascript callback for upload complete
+ ExternalInterface.call("S3SWFUploadComplete", options.key);
+ });
+
+ try {
+ // submit the post request
+ request.upload(fileReference);
+ } catch(e:Error) {
+ textInput.text = "Upload exception!";
+ trace("An error occurred: " + e);
+ }
+
+ }
+
+ ]]>
+ </mx:Script>
+
+ <mx:Label x="10" y="10" id="textInput" color="#FFFFFF" fontWeight="bold" text="Click the browser button."/>
+ <mx:Button x="217" y="8" label="Browser" click="browser();"/>
+
+</mx:Application>
Oops, something went wrong.

0 comments on commit b3432fb

Please sign in to comment.