最近做了阿里的视频接口,很蛋疼,阿里的视频获取封面图片是有时间限制的,过期就无法访问了,只能先下载后上传。
废话不多说,直接上代码
public ActionResult UploadvideoImg(String url)
{
WebRequest request = WebRequest.Create(url);
WebResponse response = request.GetResponse();
Stream reader = response.GetResponseStream();
List<byte> bytes = new List<byte>();
int temp = reader.ReadByte();
while (temp != -1)
{
bytes.Add((byte)temp);
temp = reader.ReadByte();
}
var b = bytes.ToArray();
Stream n = new MemoryStream(b);
var imgurl = OSSApi.saveFile(n, 5);//阿里的上传视频接口,我做了封装,大家知道传的是stream就行
return Json(new { imgurl = imgurl });
}