直接从Flash 403问题上传到s3

mat*_*ace 5 amazon-s3 actionscript-3

有很多方法可以从flash上​​传到S3.我正在尝试在亚马逊的网站上实现以下示例中的代码http://aws.amazon.com/code/1092?_encoding=UTF8&jiveRedirect=1

我跑过的一些帖子表明亚马逊的很多字段现在都是Requiered,除非你填写它们,否则你会得到这个可怕的403错误.

我尝试了几件事,我希望很快就会有解决方案.我从http://code.google.com/p/as3awss3lib/使用了以下库.

这是我的班级处理所有上传

package com.myemma.s3uploader.main.controllers
{
    import jp.classmethod.aws.core.AWSEvent;

    import s3.flash.S3PostOptions;
    import s3.flash.S3PostRequest;

    import utils.PolicyGenerator;

    import com.myemma.s3uploader.main.model.MainDM;
    import com.myemma.s3uploader.settings.Settings;

    import flash.events.DataEvent;
    import flash.events.Event;
    import flash.events.EventDispatcher;
    import flash.events.IOErrorEvent;
    import flash.events.ProgressEvent;
    import flash.events.SecurityErrorEvent;
    import flash.external.ExternalInterface;
    import flash.net.FileReference;

    /**
     * @author Matthew Sloan Wallace - http://mattwallace.me
     */
    public class UploadFilesAction extends EventDispatcher
    {
        [Inject]
        public var dm : MainDM;
        private var service : S3PostRequest;

        [Init]
        public function onInit() : void
        {
            if (ExternalInterface.available)
                ExternalInterface.addCallback( "uploadFiles", uploadFiles );
        }

        private function uploadFiles() : void
        {
            if (dm.selectedFiles)
                upload();
        }

        private function upload() : void
        {
            if (dm.selectedFiles.length > 0)
            {
                var fileReference : FileReference = dm.selectedFiles[0];
                // var s3:AWSS3 = new AWSS3(Settings.accessKey, Settings.secret_key);
                // s3.saveObject("mattwallace", fileReference.name, "image/png", fileReference);
                // s3.addEventListener("objectSaved", onObjectSaved);

                var policy : PolicyGenerator = PolicyGenerator.getInstance( Settings.accessKey, Settings.secret_key );
                var s3Options : S3PostOptions = new S3PostOptions();
                s3Options.secure = false;
                s3Options.acl = "private";
                s3Options.contentType = "image/png";
                s3Options.filename = fileReference.name;
                s3Options.success_action_status = "201";
                s3Options.policy = policy.policy;
                s3Options.signature = policy.signature;

                service = new S3PostRequest( Settings.accessKey, Settings.bucket, Settings.secret_key, s3Options );

                service.addEventListener( Event.OPEN, function( event : Event ) : void
                {
                    trace( "Uploading..." );
                    trace( "Upload started: " + fileReference.name );
                } );
                service.addEventListener( ProgressEvent.PROGRESS, function( event : ProgressEvent ) : void
                {
                    trace( Math.floor( event.bytesLoaded / event.bytesTotal * 100 ) );
                } );
                service.addEventListener( IOErrorEvent.IO_ERROR, function( event : IOErrorEvent ) : void
                {
                    trace( "Upload error!" );
                    trace( "An IO error occurred: " + event );
                } );
                service.addEventListener( SecurityErrorEvent.SECURITY_ERROR, function( event : SecurityErrorEvent ) : void
                {
                    trace( "Upload error!" );
                    trace( "A security error occurred: " + event );
                } );
                service.addEventListener( DataEvent.UPLOAD_COMPLETE_DATA, function( event : Event ) : void
                {
                    trace( "Upload complete!" );
                    trace( "Upload completed: " + event );
                    dm.selectedFiles.splice( 0, 1 );
                } );

                try
                {
                    service.upload( fileReference );
                }
                catch(e : Error)
                {
                    trace( "Upload error!" );
                    trace( "An error occurred: " + e );
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Eug*_*y89 0

我使用过 s3,并且没有为此使用特殊的库(也许除了生成策略和签名之外)。尝试如下操作:

var policyURL = "..."; //something like "http://domain.s3.amazonaws.com/crossdomain.xml"
flash.security.Security.loadPolicyFile(policyURL);
fileReference.addEventListener(Event.SELECT, selectHandler);
fileReference.browse();

function selectHandler(e: Event) {
    fileReference = event.target;

    s3options = new flash.net.URLVariables();
    s3Options.secure = false;
    s3Options.acl = "private";
    s3Options.contentType = "image/png";
    s3Options.filename = fileReference.name;
    s3Options.success_action_status = "201";
    s3Options.policy = policy;
    s3Options.signature = signature;

    uploadURL = new flash.net.URLRequest();
    uploadURL.data = s3Options;
    fileReference.upload(uploadURL, "file", false);
}
Run Code Online (Sandbox Code Playgroud)