使用 Adob​​e AIR 下载文件 [英] Download a file with Adobe AIR

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

问题描述

如何在基于 Flex 的 AIR 应用程序中从 Internet 下载文件.

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 的数据格式启动下载.然后,您将启动一个 Filestream 对象并使用 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 非常相似,但不是在使用结果之前等待文件完全下载,而是在下载期间向您提供数据.此方法适用于大文件,因为您不必等待完整下载即可开始将其保存到磁盘,而且您还可以节省内存,因为一旦播放器将其交给您,它就可以释放与该数据相关的内存.你会以完全相同的方式使用文件流,你最终会在文件的每个块上执行 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.

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

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