使用as3将文件上传到box api v2

时间:2012-09-27 07:31:29

标签: actionscript-3 box-api

我正在尝试使用v2将文件上传到邮箱。我得到的唯一结果是上传时出错。我能够进行身份验证,获取身份验证令牌但无法上传,我已经提供了我正在使用的代码。如果我错了,请纠正我。任何帮助将不胜感激!!

    public function upload(argFile:flash.filesystem.File):void{ 

        argFile.addEventListener(Event.COMPLETE,
            function onComplete(event:Event):void
            {
                trace("complete:"+event.toString());
            }
        ); 
        argFile.addEventListener(IOErrorEvent.IO_ERROR,
            function onIOError(event:IOErrorEvent):void
            {
                trace("Error:"+event.toString());
            }
        ); 


        var url:String = "https://api.box.com/2.0/files/data";  

        // Setup the custom header 
        var customHeader:String = "BoxAuth api_key=" + api_key + "&auth_token=" + auth_token;
        var headers:Array = [ 
            new URLRequestHeader("Authorization", customHeader) 
        ]; 

        // create the url-vars 
        var urlVars:URLVariables = new URLVariables(); 
        urlVars.filename1 = '@'+argFile.name; 
        urlVars.folder_id = "0"; 

        // create the url-reqeust 
        var request:URLRequest = new URLRequest(); 
        request.contentType = "application/octet-stream"; 
        request.method = URLRequestMethod.POST; 

        // set ther url 
        request.url = url; 

        // set the header 
        request.requestHeaders = headers; 

        // set the vars 
        request.data = urlVars; 
        try { 
            argFile.upload(request); 
        } catch (e:Error) 
        { 
            trace(e.toString(), "Error (catch all)"); 
        } 
    } 

0 个答案:

没有答案