1.后端接收(zip)
[Route("Upload")]
[HttpPost]
[AllowAnonymous]
public string Upload()
{
try
{
HttpRequest request = HttpContext.Current.Request;//获取请求对象
//var ddf = long.Parse(request.Headers["token"]);
//if ((ddf & 178) == 178)
//{
HttpFileCollection fileCollection = request.Files;//获取对象集
Stream fs = fileCollection[0].InputStream;//获取单一对象
Byte[] imagebytes = new byte[fs.Length];//读取字符流的长度
BinaryReader br = new BinaryReader(fs); //文件
imagebytes = br.ReadBytes(Convert.ToInt32(fs.Length));//赋值字符流
string filesname = Guid.NewGuid().ToString().Replace("-", "");
string url = HttpRuntime.AppDomainAppPath.ToString();
Bytes2File(imagebytes, url+ @"\file\" + filesname+".zip");
string Url = ""; // return request.Url.Scheme +"://" +request.Url.Authority + "/images/" + name + tyle;//返回带服务器的地址
Url = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + "/file/" + filesname + ".zip";//返回带服务器的地址
return Url;
}
catch(Exception e)
{
return null;
}
}
/// <summary>
/// 将byte数组转换为文件并保存到指定地址
/// </summary>
/// <param name="buff">byte数组</param>
/// <param name="savepath">保存地址</param>
public static void Bytes2File(byte[] buff, string savepath)
{
if (System.IO.File.Exists(save