Asp.net mvc 3 如何将jpg从web下载到MVC3中的项目文件夹?
大家好,我想问一下,如何将.jpg文件从web下载到我创建的“上载”项目文件夹中 我正在尝试将youtube缩略图下载到我的“上传”文件夹中 我的控制器:Asp.net mvc 3 如何将jpg从web下载到MVC3中的项目文件夹?,asp.net-mvc-3,Asp.net Mvc 3,大家好,我想问一下,如何将.jpg文件从web下载到我创建的“上载”项目文件夹中 我正在尝试将youtube缩略图下载到我的“上传”文件夹中 我的控制器: var fileName = Path.GetFileName(http://img.youtube.com/vi/RUgd_GDPhYk/1.jpg); var path = Path.Combine(Server.MapPath("~/uploads/"), fileName); file.Save
var fileName = Path.GetFileName(http://img.youtube.com/vi/RUgd_GDPhYk/1.jpg);
var path = Path.Combine(Server.MapPath("~/uploads/"), fileName);
file.SaveAs(path);
看看
System.Net.WebClient
,它是一个.Net类,允许您通过HTTP请求资源
检查提供的示例
var client = new System.Net.WebClient();
var uri = "http://img.youtube.com/vi/RUgd_GDPhYk/1.jpg";
// Here, we're just using the same filename as the resource we're after.
// You may wish to change this to include extra stuff because you'll
// inevitably run into a naming clash - especially with stuff like 1.jpg
var targetFilename = Path.GetFileName(uri);
client.DownloadFile(uri,
Path.Combine(Server.MapPath("~/uploads"), targetFilename));