上传图片
public string Base64StringToImageUser(HttpServerUtilityBase Server, string strbase64)
{
try
{
var tmpArr = strbase64.Split(',');
string value = "";
if (strbase64 != null && strbase64 != "")
{
byte[] arr = Convert.FromBase64String(strbase64.Split(',')[1]);
MemoryStream ms = new MemoryStream(arr);
Image img = Image.FromStream(ms);
System.Drawing.Bitmap image = new System.Drawing.Bitmap(img);
string filename;//带后缀的图片名
string path;//图片完整路径
image.Save(path);
ms.Close();
value =path;
return value;
}
else
{
return value;
}
}
catch (Exception ex)
{
return ex.ToString();
}
}
上传视频
public string Base64StringToVideo(HttpServerUtilityBase Server,string strbase64)
{
try
{
var tmpArr = strbase64.Split(',');
string value = "";
if (strbase64 != null && strbase64 != "")
{
byte[] arr = Convert.FromBase64String(strbase64.Split(',')[1]);
string filename;//带后缀的视频名
string path;//图片完整路径
FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write);
fs.Write(arr, 0, arr.Length);
fs.Close();
value = path;
return value;
}
else
{
return value;
}
}
catch (Exception ex)
{
return ex.ToString();
}
}
文本普通上传
public string UploadText(HttpServerUtilityBase Server,string DetailContent)
{
try
{
//txt文件名称
string WareDepictfileName = DateTime.Now.ToString("yyyy-MM-dd") + "-" + Guid.NewGuid() + ".txt";
//txt文件完整路径
string WareDepictfilePath;
//txt文件内容
string textCount = DetailContent;
//保存文件 txt文件
TextWriter textWriter = new StreamWriter(WareDepictfilePath, false, new System.Text.UTF8Encoding(false));
textWriter.Write(textCount);
textWriter.Close();
return WareDepictPath;
}
catch (Exception)
{
throw;
}
}