FLEX中的文件上载不允许大小超过1MB的文件

时间:2014-06-23 12:47:40

标签: actionscript-3 flex flex4.5

我使用base64Encoder使用flex上传文件。但是当文件大小超过1MB时,将数据放在HTTPService上作为参数时显示错误。请帮忙。提前谢谢。

显示以下错误: 错误:[IOErrorEvent type =“ioError”bubbles = false cancelable = false eventPhase = 2 text =“错误#2032:流错误。

我写的功能如下:

    protected function uploadButton_clickHandler(event:Event):void{
            try{
                var uniqueRowId:String=parentApplication.dg.dataProvider[parentApplication.dg.selectedIndex].UNIQUEROWID;
                var propObj:Object = parentApplication.propertyDict[uniqueRowId];
                fileRef = propObj["fileRef_"+uniqueRowId];

                fileRef.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,onUploadComplete);
                fileRef.addEventListener(IOErrorEvent.IO_ERROR,onIOError);

                var selectedAttachment : String = propObj["selectedObjectStr_"+uniqueRowId];
                var UPLOAD_URL:String="/MDOSF/Customer_tab.do"; 
                var ext:String = selectedAttachment.substr(selectedAttachment.lastIndexOf("."), selectedAttachment.length);
                ext = ext.toLowerCase();                    
                var imgByteArr:ByteArray = event.target.data;
                var encoder:Base64Encoder = new Base64Encoder();    
                var totalBytes:uint = imgByteArr.length;
                var limitBytes:String = String((totalBytes/1024)/1024);
                var numericBytes:Number =Number(limitBytes);
                var decimal:String = numericBytes.toFixed(2);
                if(Number(decimal) > 1){
                    //Alert.show("Cannot upload file with size more than 1 MB","Message");
                    //return;
                }
                encoder.encodeBytes(imgByteArr);                    
                var params:Object = new Object();
                params.fileName = encodeURIComponent(selectedAttachment);
                params.ext = ext;
                params.file_data = encodeURIComponent(encoder.flush());
                params.action = "saveAttachment";
                params.GRID_PARAM = "fromGrid";
                params.selectedFile = encodeURIComponent(selectedAttachment);
                params.gridName = parentApplication.fieldName;
                uploadImageService.url = UPLOAD_URL;
                uploadImageService.send(params);

            }catch(err:Error){
            }
        }

1 个答案:

答案 0 :(得分:0)

大多数网络服务器限制GET requests to 8KB(但服务器可能非常)。默认情况下,HTTPService uses GET method。我建议添加:

uploadImageService.method = 'POST';

在您致电uploadImageService.send(params);之前,您还需要调整您的Java代码以使用GET上的POST方法。