今天ipad那面想做下webservice上传图片,我这面要做个测试的接口,用于测试
图片是以16进制的字符串传过来,并同时传进来文件名称,因为只是测试所以,最简单的写了一个
[WebMethod]
public void UploadFile(string fs,string fileName)
{
byte[] baseBytes = Hex2ByteArr(fs.Replace(" ", ""));
FileStream f = new FileStream(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,fileName), FileMode.OpenOrCreate, FileAccess.Write);
BinaryWriter w = new BinaryWriter(f);
w.Write(baseBytes);
w.Flush();
f.Close();
}
public byte[] Hex2ByteArr(string newString)
{
int len = newString.Length / 2;
byte[] arr = new byte[len];
for (int i = 0; i < len; i++)
{
arr[i] = Convert.ToByte(newString.Substring(i * 2, 2), 16);
}
return arr;
}