首页 > 移动平台 > 详细

android 上传图片

时间:2020-01-14 17:44:30      阅读:65      评论:0      收藏:0      [点我收藏+]

1.先用html的原始标签来完成上传图片功能,后台使用asp.net.

2.再用android的okhttp来代替html。

html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>HTML控件配合ASP。NET 上传</title>
</head>
<body>
<form name="uploadForm" method="post" enctype="multipart/form-data" action="http://localhost/upload/Default.aspx">
    <input id="name" name="name" style="width:220px;" />
    <input type="file" id="imgFile" name="imgFile" style="width:220px;" />
    <input type="file" id="imgFile2" name="imgFile2" style="width:220px;" />
    <input type="file" id="imgFile3" name="imgFile3" style="width:220px;" />
    <input type="submit" value="submit" />
</form>
</body>
</html>

 

 

asp.net 的后端

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="upload._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </div>
    </form>
</body>
</html>

 

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace upload
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                string name=this.Request.Form.Get("name");
                string path = Server.MapPath("");
                this.Label1.Text = "name:" + name + ".path:" + path;

                if (this.Request.Files.Count > 0)
                {
                    for (int i = 0; i < this.Request.Files.Count;i++ )
                    {
                        HttpPostedFile file = this.Request.Files.Get(i);
                        string pathstr = path + "/aaupload"+System.DateTime.Now.ToFileTime().ToString() +"index"+  i.ToString()+ ".png";
                        try
                        {
                            file.SaveAs(pathstr);
                        }
                        catch
                        {
                            this.Label1.Text ="error:"+pathstr;
                        }
                    }
                }
            }
        }
    }
}

 

android 上传图片

原文:https://www.cnblogs.com/lsfv/p/12193171.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!