下载与Adobe AIR文件 [英] Download a file with Adobe AIR

查看:205
本文介绍了下载与Adobe AIR文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何从网上下载一个文件,在基于Flex的AIR应用程序。

How do I download a file from the internet in a Flex based AIR application.

我尝试使用与URL设置为地址的文件,但我得到了一个文件不存在错误,当我试图挽救它。它是真的很难谷歌在这个问题上的帮助。

I tried using a file with url set to the address, but I got a file does not exist error when I tried to save it. And it is really hard to google for help on this issue.

推荐答案

您想从2 API组合来选择做到这一点。

You want to choose from 2 api combos to accomplish this.

1版是URLLoader和的FileStream

Version 1 is URLLoader and FileStream

使用这个类的组合,你会通过URLLoader对象加载从你的服务器上的文件到空气中。这将下载文件到内存,然后通知您下载完毕。请确保您启动下载与URLLoaderDataFormat.BINARY的DATAFORMAT。这样,你会发起一个文件流对象,并写入到使用磁盘writeBytes()。

Using this combination of class, you would load the file from your server in to air via the URLLoader object. This will download the file in to memory and then notify you when the download is complete. Make sure you initiate the download with a dataFormat of URLLoaderDataFormat.BINARY. You would then initiate a Filestream object and write it out to the disk using writeBytes().

2版是URLStream和的FileStream

Version 2 is URLStream and FileStream

URLStream非常类似的URLLoader,但不是在等待该文件使用的结果之前完全下载,数据在下载过程中提供给您。这种方法适用于大型文件,因为你不必等待完全下载后才能启动它保存到磁盘,而且你还可以节省内存,因为一旦球员递给关你就可以释放与数据存储器。你会使用FILESTREAM在完全相同的方式,你会只落得做writeBytes()上的文件的每个块,因为它在流。

URLStream is very similar to URLLoader, but instead of waiting for the file to completely download before using the result, data is made available to you during the download. This method works well for large files because you don't have to wait for the full download to start saving it to disk, and you also save on memory since once the player hands it off to you it can release the memory related to that data. YOu would use filestream in exactly the same way, you would just end up doing a writeBytes() on each chunk of the file as it streams in.

这篇关于下载与Adobe AIR文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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