加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

actionscript-3 – 直接从Flash 403问题上传到s3

发布时间:2020-12-15 07:27:39 所属栏目:百科 来源:网络整理
导读:有很多方法可以从flash上??传到S3.我正在尝试在Amazon的网站 http://aws.amazon.com/code/1092?_encoding=UTF8jiveRedirect=1上实现以下示例中的代码 我跑过的一些帖子表明亚马逊的很多字段现在都是Requiered,除非你填写它们,否则你会得到这个可怕的403错误.
有很多方法可以从flash上??传到S3.我正在尝试在Amazon的网站 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 );
                }
            }
        }
    }
}

解决方法

我曾与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);
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读