使用XMLHTTPRequest下载图像 [英] Download image using XMLHTTPRequest

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

问题描述

我正在使用iphone的phonegap应用程序,但现在我有麻烦找到一个方法,从服务器下载图像到iphone图库...

I'm working on an phonegap app for iphone, But, now i'm in trouble to find a way do download images from the server to the iphone gallery...

我有这些小代码获取文件内容:

I have these small code that gets the file content:

var req = new XMLHttpRequest();  
req.open('GET',"http://site.com/imagefile.jpg", false);   
req.send(); 

但是,我不知道如何强制保存它。
如果不可能这样,我也可以得到编码为base64的图像文件...我不认为这将有助于一些。

But, I dont know how to force to save it. If not possible this way, I can also get the image file codeded into base64... I dont think if this will help something.

你能请,给我一些解释?

Could you please, give me some explanation?

我搜索了很多,但我没有找到样本...

I googled a lot, but I didnt find samples...

推荐答案

你不能保存到iphone照片的文件夹Phonegap(至少没有写一个扩展)。所以你不能真正保存的照片到一个文件(再没有扩展名),唯一真正的方式来保存在跨平台(照片,因此phonegap html& Javascript的方式)照片的方式是将它们保存到本地sqlite数据库。请参阅Jesse MacFayden在 Phonegap上执行此操作的文章网站。 Jesse将图像实际保存到数据库,并将其作为读者的工作加载,但如果您有问题,我只是写了一个关于如何使用在Phonegap中的数据库今天上午。

You can't save to iphone photo's folder with Phonegap (without writing an extension at least). So you can't really save the photo's to a file (again without an extension), the only real way to save photos in a cross-platform (and thus phonegap html & Javascript way) way is to save them to a local sqlite database. See Jesse MacFayden's article on doing this on the Phonegap site. Jesse leaves the actual saving of the image to database and loading it as a work for the reader, but if you have problems with that I just wrote an answer on how to use the database in Phonegap just this morning.

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

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