在Mac OS上的flex air应用程序中文件上传URL请求问题?但可在Windows中使用. [英] file upload url request problem in flex air application on mac os?but works in windows..

查看:94
本文介绍了在Mac OS上的flex air应用程序中文件上传URL请求问题?但可在Windows中使用.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是Flex air应用程序

我必须使用浏览按钮上传图像,以便所选文件作为字节数组存储在本地数据库中.
我正在urlloader中加载该文件的URL.在Windows中仍然没有问题,一切正常,但在MAC OS中却无法正常工作.那是URL错误.我使用Google搜索.错误在URL路径中.

Hi,

This is a Flex air application

I have to upload the image using browse button so that the selected file is stored in local database as byte array.
I am loading that file''s URL in urlloader. still no problem in Windows, everything works fine, but in MAC OS it is not working. That is URL error. I searched using Google. The error is in URL path.

// browse button function.
public function browse_file(eve:MouseEvent):void{
				file1 = File.documentsDirectory;
				file1.addEventListener(Event.SELECT, handleSelectFile);
				file1.browseForOpen("Select Picture");
			}
			public function handleSelectFile(event:Event):void
			{
				file_name.text = event.target.nativePath;
				fname=event.target.name;
				fnamearr.push(event.target.name);
				var request:URLRequest = new
					URLRequest(file_name.text);
				var urlLoader:URLLoader = new URLLoader(request);//===>(here is the error in loading path in mac.. URLLoader IOErrorEvent.IO_ERROR.)
				
				urlLoader.addEventListener(Event.COMPLETE,
					onURLLoaderComplete);
				urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
				urlLoader.load(request);
				
			}

private function onURLLoaderComplete(event:Event):void
			{
				loadedFile = event.target.data;
				var encoder:Base64Encoder=new Base64Encoder();
				encoder.encodeBytes(loadedFile);
				byte=encoder.toString();
				bytesarr.push(byte);
				//byte=encoder.encode(loadedFile);
				
				Alert.show('==>'+file_name.text);
			}

推荐答案

在您的代码中修改以下内容:

公共变量os:String = flash.system.Capabilities.os.substr(0,3);

if(os =="Win"){
file_name.text = event.target.nativePath;
}
否则if(os =="Mac" || os =="Lin"){
file_name.text = event.target.url;
}
modify the following in your code:

public var os:String = flash.system.Capabilities.os.substr(0, 3);

if(os=="Win" ){
file_name.text = event.target.nativePath;
}
else if(os=="Mac"|| os=="Lin"){
file_name.text = event.target.url;
}


这篇关于在Mac OS上的flex air应用程序中文件上传URL请求问题?但可在Windows中使用.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆