图片上传的实现

如何实现图片上传至服务器 发表文章时上文章封面时上用户头像时通过编辑器的菜单添加图片。直接复制一张图片粘贴到编辑器中复制外部的图片链接(markdown格式),到编辑器中。导入MD文件到编辑器中(如果图片有连接时)。这四种方式都会出发图片上传功能(严格一点,后面两个还涉及到图片转链)后台的接口都是一样的,都调用的是ImageRestController,上图片调用的是upload方法,请求参数为HttpServletRequest;转存图片链接调用的是save方法,参数为图片的外部链接。 阅读详情
图片上传的功能简介及web.config设置(自动生成所略图)
程序代码:
功能:
1。把图片文件(JPG GIF PNG)上传,
2。保存到指定的路径(在web.config中设置路径,以文件的原有格式保存),
3。并自动生成指定宽度的(在web.config中设置宽度)
4。和指定格式的(在web.config中指定缩略图的格式,支持GIF,JPG,PNG)
5。和原图比例相同的缩略图(根据宽度和原图的宽和高计算所略图的高度)
6。可以判断是否已经存在文件
7。如果不覆盖,则给出错误
8。如果选中"覆盖原图"checkbox,则覆盖原图。
9。可以根据要求,在webform上设置1个以上的file input和相应的checkbox
10。并在文件上传完毕后,显示原图的文件名,尺寸,字节,和
11。缩略图的文件名尺寸,以及
12。显示原图和缩略图。
13。缩略图的文件名格式,以便与管理:
    大图(原图): 图片分类代号_图片代表的日期_图片原有文件名.原有格式 (如:28_2002-1-28_test.jpg)
    缩略图:          图片分类代号_图片代表的日期_图片原有文件名.原有格式_thumb.指定的缩略图格式 (如:28_2002-1-28_test.jpg_thumb.gif)

----------------------
web.config文件中的相应设置:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.web> 
    ...
    ...
    </system.web>
    <appSettings>
        ...
        ...
        ...
        ...
        //FePicSavePath 图片保存在服务器上的实际路径
        <add key="FePicSavePath" value="d:/myroot/myapp/content/fepics/" />
        //FePicWebPath 图片的网络路径,用于显示图片
        <add key="FePicWebPath" value=" http://www.mysite.com/fepics/" />
        //FePicThumbWidth 缩略图的宽度
        <add key="FePicThumbWidth" value="115" />
        //所略图的格式
        <add key="FePicThumbFormat" value="gif" />    
    </appSettings>
</configuration>


图片上传的数据库部分(自动生成所略图)

程序代码:
  public int FePicDataSet(string strPicTitle, string strPicDate, string strPicName, int intPicType, string strPicIntro, string strThumbnail, int opID) 
        {

            //string strPicTitle, 
            //string strPicDate, 
            //string strPicName, 
            //int intPicType, 
            //string strPicIntro, 
            //string strPicName, 
            //string strThumbnail, 
            //int opID
            SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
            SqlCommand myCommand = new SqlCommand("mag_FePicDataSet", myConnection);
            // Mark the Command as a SPROC
            myCommand.CommandType = CommandType.StoredProcedure;

            // Add Parameters to SPROC
            SqlParameter parameterUserId = new SqlParameter("@opID", SqlDbType.Int);
            parameterUserId.Value = opID;
            myCommand.Parameters.Add(parameterUserId);
            
            SqlParameter parameterPicTitle = new SqlParameter("@picTitle", SqlDbType.Char, 30);
            parameterPicTitle.Value = strPicTitle;            
            myCommand.Parameters.Add(parameterPicTitle);

            SqlParameter parameterPicDate = new SqlParameter("@picDate", SqlDbType.Char, 10);
            parameterPicDate.Value = strPicDate;
            myCommand.Parameters.Add(parameterPicDate);        

            SqlParameter parameterPicName = new SqlParameter("@picName", SqlDbType.Char, 50);
            parameterPicName.Value = strPicName;
            myCommand.Parameters.Add(parameterPicName);        

            SqlParameter parameterPicType = new SqlParameter("@picType", SqlDbType.Int);
            parameterPicType.Value = intPicType;
            myCommand.Parameters.Add(parameterPicType);        

            SqlParameter parameterPicIntro = new SqlParameter("@picIntro", SqlDbType.Char, 255);
            parameterPicIntro.Value = strPicIntro;
            myCommand.Parameters.Add(parameterPicIntro);
        
            SqlParameter parameterThumbnail = new SqlParameter("@thumbnail", SqlDbType.Char, 50);
            parameterThumbnail.Value = strThumbnail;
            myCommand.Parameters.Add(parameterThumbnail);        

            SqlParameter parameterHostAddress = new SqlParameter("@opIP", SqlDbType.Char, 15);
            parameterHostAddress.Value = Context.Request.UserHostAddress;                
            myCommand.Parameters.Add(parameterHostAddress);    

            //SqlParameter parameterRID = new SqlParameter("@returnID", SqlDbType.Int);
            //parameterReturnUserID.Value = -1;
            //parameterRID.Direction = ParameterDirection.Output;
            //myCommand.Parameters.Add(parameterRID);

            
            
            // Execute the command in a try/catch to catch duplicate username errors
            try 
            {
                // Open the connection and execute the Command
                myConnection.Open();
                myCommand.ExecuteNonQuery();
            }
            catch 
            {

                // failed to create a new user
                return -1;
            }
            finally 
            {

                // Close the Connection
                if (myConnection.State == ConnectionState.Open)
                    myConnection.Close();
            }

            return 1;

        }


图片上传的Codebehind(自动生成所略图)

程序代码:
using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text;
using cj168.util;


namespace cj168.Web.Mag.Admins.FeData
{
    /// <summary>
    /// Summary description for fedata.
    /// </summary>
    public class feUploadPic : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.TextBox txtboxPicTitle;
        protected System.Web.UI.WebControls.Calendar calPicDate;
        protected System.Web.UI.WebControls.DropDownList ddlPicType;
        protected System.Web.UI.WebControls.TextBox txtboxPicIntro;
        protected System.Web.UI.HtmlControls.HtmlInputFile filePicName;
        protected System.Web.UI.WebControls.Button btnSubmit;
        protected System.Web.UI.WebControls.Label lblPicInfo;
        protected System.Web.UI.WebControls.TextBox txtboxPicDate;
        protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator1;
        protected System.Web.UI.WebControls.RegularExpressionValidator vldCatName;
        protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator2;
        protected System.Web.UI.WebControls.CustomValidator CustomValidator1;
        protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
        protected System.Web.UI.WebControls.HyperLink hlkOriPic;
        protected System.Web.UI.WebControls.HyperLink hlkNewPic;
        protected System.Web.UI.WebControls.RegularExpressionValidator Regularexpressionvalidator2;
        protected System.Web.UI.WebControls.RegularExpressionValidator Regularexpressionvalidator3;
        protected System.Web.UI.WebControls.CheckBoxList checkboxlistRewrite;
        
        
    
        private void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here
            //if(Page.IsPostBack)
            //txtboxPicDate.Text = calPicDate.SelectedDate.ToString(); 

            if(!Page.IsPostBack)
            {
                Bind2DropDownListPicType();

                //for(int i = 0;i < Request.Files.Count; i++)
                //{                
                //    checkboxlistRewrite.Items.Selected = false;
                //}
            }


            


        }

        public void Bind2DropDownListPicType()
        {
            cj168.DataAccess.Admins admins = new cj168.DataAccess.Admins();
            DataSet ds = admins.FePicTypeGet();
            //ddlPicType.DataSource = ;
            DataView dv = new DataView(ds.Tables["PicType"]);
            
            DataRowView drv = dv.AddNew();
            //DataColumnView dcv = dv.AddNew();
            drv["Title"] = "请选择";
            drv["fePicTypeID"] = "0";
            drv.EndEdit();            
            

            dv.Sort = "fePicTypeID";            

            ddlPicType.DataSource = dv;

            ddlPicType.DataBind();
        }

        public void UploadFile(object sender, System.EventArgs e)
        {
            
                string imgNameOnly, imgNameNoExt, imgExt;
                string imgThumbnail;
                int erroNumber = 0;
                System.Drawing.Image oriImg, newImg;
                string strFePicSavePath = ConfigurationSettings.AppSettings["FePicSavePath"].ToString();
                string strFePicThumbFormat = ConfigurationSettings.AppSettings["FePicThumbFormat"].ToString().ToLower();
                int intFeThumbWidth = Int32.Parse(ConfigurationSettings.AppSettings["FePicThumbWidth"]);
                string fileExt;
                string strPicTitle = txtboxPicTitle.Text;
                string strPicIntro = txtboxPicIntro.Text;
                string strPicDate = txtboxPicDate.Text;

                int intPicType = Int32.Parse(ddlPicType.SelectedItem.Value);
                string strPicType = intPicType.ToString() + "_" + DateTime.Now.Date.ToShortDateString() + "_";
                string strFePicWebPath = ConfigurationSettings.AppSettings["FePicWebPath"];

                cj168.DataAccess.Admins admins = new cj168.DataAccess.Admins();
                
                //if(admins.FePicTypeSet(textboxTitle.Text,0) < 0)
                //    lblAddPicInfo.Text = "操作失败:已经存在相同名称类型,请修改";
                //else
                //    lblAddPicInfo.Text = "操作成功";


                StringBuilder picInfo = new StringBuilder();

            
            
            if(Page.IsValid)
            {
            

                for(int i = 0;i < Request.Files.Count; i++)
                {
                    HttpPostedFile PostedFile = Request.Files;
                    fileExt = (System.IO.Path.GetExtension(PostedFile.FileName)).ToString().ToLower();
                    //5-test.jpg
                    imgNameOnly = strPicType + System.IO.Path.GetFileName(PostedFile.FileName);
                    if(fileExt == ".jpg" || fileExt == ".gif" || fileExt == ".png")
                    {

                        if(System.IO.File.Exists(strFePicSavePath + imgNameOnly) && (checkboxlistRewrite.Items.Selected == false))
                        {
                            erroNumber = erroNumber + 1;
                            picInfo.Append("<b>错误:</b>文件("+ (i+1) +") " + imgNameOnly + " 已经存在,请修改文件名<br>" );
                        }
                    }
                    else
                    {
                        erroNumber = erroNumber + 1;
                        if(fileExt == "")
                            picInfo.Append("<b>错误:</b>请选择文件<br>" );
                        else
                        picInfo.Append("<b>错误:</b>文件("+ (i+1) +") " + imgNameOnly + " 扩展名 " + fileExt + " 不被许可<br>" );
                    }                

                }

                if(erroNumber > 0) 
                {
                    picInfo.Append("<font color=red>全部操作均未完成,请修改错误,再进行操作</font><br>");

                    hlkOriPic.ImageUrl = "";
                    hlkOriPic.ToolTip = "";
                    hlkNewPic.ImageUrl = "";
                    hlkNewPic.ToolTip = "";
                }
                else            
                {
                    for(int i = 0;i < Request.Files.Count; i++)
                    {
                
                        HttpPostedFile PostedFile = Request.Files;
                        imgNameOnly = strPicType + System.IO.Path.GetFileName(PostedFile.FileName);
                        imgNameNoExt = System.IO.Path.GetFileNameWithoutExtension(PostedFile.FileName);
                        imgExt = System.IO.Path.GetExtension(PostedFile.FileName).ToString().ToLower();
                    
                    
                        oriImg = System.Drawing.Image.FromStream(PostedFile.InputStream);
                        newImg = oriImg.GetThumbnailImage(intFeThumbWidth, intFeThumbWidth * oriImg.Height/oriImg.Width,null,new System.IntPtr(0));
                        switch(imgExt)
                        {
                            //case ".jpeg":
                            case ".jpg":
                                oriImg.Save(strFePicSavePath + imgNameOnly , System.Drawing.Imaging.ImageFormat.Jpeg);
                                break;
                            case ".gif":
                                oriImg.Save(strFePicSavePath + imgNameOnly , System.Drawing.Imaging.ImageFormat.Gif);
                                break;
                            case ".png":
                                oriImg.Save(strFePicSavePath + imgNameOnly , System.Drawing.Imaging.ImageFormat.Png);
                                break;
                        }
                        
                        //oriImg.Save(ConfigurationSettings.AppSettings["FePicSavePath"] + imgNameNoExt + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
                        
                                        
                        switch(strFePicThumbFormat)
                        {
                                //jpeg format can get the smallest file size, and the png is the largest size
                            //case "jpeg":
                            case "jpg":
                                newImg.Save(strFePicSavePath + imgNameOnly + "_thumb.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
                                imgThumbnail = imgNameOnly + "_thumb.jpg";
                                break;
                            case "gif":
                                newImg.Save(strFePicSavePath + imgNameOnly + "_thumb.gif",System.Drawing.Imaging.ImageFormat.Gif);
                                imgThumbnail = imgNameOnly + "_thumb.gif";
                                break;
                            case "png":
                                newImg.Save(strFePicSavePath + imgNameOnly + "_thumb.png",System.Drawing.Imaging.ImageFormat.Png);
                                imgThumbnail = imgNameOnly + "_thumb.png";
                                break;
                            default:
                                newImg.Save(strFePicSavePath + imgNameOnly + "_thumb.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
                                imgThumbnail = imgNameOnly + "_thumb.jpg";                        
                                break;
                    
                        }//switch
                        
                        picInfo.Append("<b>文件 名:</b>" + imgNameOnly + " ( " + oriImg.Width + " x " + oriImg.Height + " ) " + PostedFile.ContentLength/1024 + "KB<br>");
                        picInfo.Append("<b>缩略图名:</b>" + imgThumbnail + " ( " + newImg.Width + " x " + newImg.Height + " )<br><br>");

                        hlkOriPic.ImageUrl = strFePicWebPath + imgNameOnly;
                        hlkOriPic.ToolTip = "◆原图◆n文件名:" + imgNameOnly + "n尺寸:" + oriImg.Width + " x " + oriImg.Height + "n字节:" + PostedFile.ContentLength/1024 + "KB";
                        hlkNewPic.ImageUrl = strFePicWebPath + imgThumbnail;
                        hlkNewPic.ToolTip = "◆缩略图◆n文件名:" + imgThumbnail + "n尺寸:" + newImg.Width + " x " + newImg.Height;
                        

                        oriImg.Dispose();
                        newImg.Dispose();
                        picInfo.Append("<font color=red>图片上传成功</font><br>");
                        if(admins.FePicDataSet(strPicTitle, strPicDate, imgNameOnly, intPicType, strPicIntro, imgThumbnail,0) < 0)
                            picInfo.Append("<font color=red>保存信息到数据库失败</font><br>");
                        else
                            picInfo.Append("<font color=red>保存信息到数据库成功</font><br>");
                    
                    }//for 
                    picInfo.Append("<font color=red>所有操作成功</font><br>");

                }// if erronumber = 0

            
                
            }
            else
            {
                picInfo.Append("<font color=red>有错误,请检查。操作未成功</font><br>");

                hlkOriPic.ImageUrl = "";
                hlkOriPic.ToolTip = "";
                hlkNewPic.ImageUrl = "";
                hlkNewPic.ToolTip = "";

            }

            for(int i = 0;i < Request.Files.Count; i++)
            {                
                checkboxlistRewrite.Items.Selected = false;
            }

            lblPicInfo.Text = picInfo.ToString();

        }

        public void CalDateSelected(object sender,System.EventArgs e)
        {
            txtboxPicDate.Text = calPicDate.SelectedDate.ToShortDateString(); 

        }

        public void ServerValidateCheckDate(object sender, System.Web.UI.WebControls.ServerValidateEventArgs value)
        {
            cj168.util.iUtil iUtils = new cj168.util.iUtil();
            if(!iUtils.IsDate(value.Value)) 
                value.IsValid = false;
            else
                value.IsValid = true;

        }

        


        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }
        
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
                                                                    {    
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion
    }
}

图片上传的WebForm(自动生成所略图)

程序代码:
<%@ Page language="c#" Codebehind="feUploadPic.aspx.cs" AutoEventWireup="false" Inherits="cj168.Web.Mag.Admins.FeData.feUploadPic" %>
<%@ Register TagPrefix="cj168" TagName="Header" Src="modules/headerFe.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
    <HEAD>
        <title>fedata</title>
        <meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
        <meta content="C#" name="CODE_LANGUAGE">
        <meta content="JavaScript" name="vs_defaultClientScript">
        <meta content=" http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
        <style>BODY { FONT-SIZE: 9pt }
    .calPicDate { FONT-SIZE: 9pt; FONT-FAMILY: Verdana, Helvetica, sans-serif }
    .valid { FONT-SIZE: 9pt; COLOR: red }
    TD { FONT-SIZE: 9pt }
        </style>
    </HEAD>
    <body MS_POSITIONING="GridLayout">
        <table width="100%">
            <tr>
                <td><cj168:header id="Header1" runat="server"></cj168:header></td>
            </tr>
        </table>
        <form id="fedata" method="post" encType="multipart/form-data" runat="server">
            <TABLE id="Table1" cellSpacing="0" cellPadding="1" width="750" border="1">
                <TR>
                    <TD width="70">图片标题</TD>
                    <TD><asp:textbox id="txtboxPicTitle" runat="server"></asp:textbox><br>
                        <asp:requiredfieldvalidator id="Requiredfieldvalidator1" runat="server" ErrorMessage="请填写图片标题。" CssClass="valid" ControlToValidate="txtboxPicTitle"></asp:requiredfieldvalidator><br>
                        <asp:regularexpressionvalidator id="vldCatName" ErrorMessage="图片标题至少2个字符,不应包含'“ ” ! @ # $ % ^ & * ( ) < > 《 》{ } [ ] ? 。,? ¥" CssClass="valid" ControlToValidate="txtboxPicTitle" ValidationExpression="[^'^“^”^^!^@^#^$^%^^^&^*^(^)^<^>^《^》^?^。^,^?^¥^{^}^][^]]{2,}" Runat="server"></asp:regularexpressionvalidator></TD>
                </TR>
                <TR>
                    <TD>图片日期</TD>
                    <TD><asp:textbox id="txtboxPicDate" runat="server" Width="300"></asp:textbox><asp:calendar id="calPicDate" runat="server" CssClass="calPicDate" Width="300" SelectMonthText="本月" SelectWeekText="本周" NextPrevFormat="FullMonth" OnSelectionChanged="CalDateSelected">
                            <NextPrevStyle CssClass="calPicDate"></NextPrevStyle>
                            <WeekendDayStyle ForeColor="red"></WeekendDayStyle>
                            <TodayDayStyle Font-Bold="True" ForeColor="red" BackColor="#ccccff"></TodayDayStyle>
                            <SelectedDayStyle BackColor="black" Font-Bold="true"></SelectedDayStyle>
                        </asp:calendar><BR>
                        <asp:requiredfieldvalidator id="Requiredfieldvalidator2" runat="server" ErrorMessage="请选择或填写图片日期。" CssClass="valid" ControlToValidate="txtboxPicDate"></asp:requiredfieldvalidator><br>
                        <asp:customvalidator id="CustomValidator1" ErrorMessage="不是个有效的日期格式" CssClass="valid" ControlToValidate="txtboxPicDate" Runat="server" OnServerValidate="ServerValidateCheckDate"></asp:customvalidator></TD>
                </TR>
                <TR>
                    <TD>图片分类</TD>
                    <TD><asp:dropdownlist id="ddlPicType" runat="server" DataValueField="fePicTypeID" DataTextField="Title"></asp:dropdownlist><FONT face="宋体"> </FONT><asp:regularexpressionvalidator id="RegularExpressionValidator1" ErrorMessage="请选择图片分类" CssClass="valid" ControlToValidate="ddlPicType" ValidationExpression="[^0]{1,}" Runat="server"></asp:regularexpressionvalidator></TD>
                </TR>
                <TR>
                    <TD>图片介绍</TD>
                    <TD><asp:textbox id="txtboxPicIntro" runat="server" MaxLength="255" TextMode="MultiLine" Columns="50" Rows="5"></asp:textbox>
                        <asp:RegularExpressionValidator id="Regularexpressionvalidator2" Runat="server" CssClass="valid" ErrorMessage="内容中不应包含 ' <  >" ControlToValidate="txtboxPicIntro" ValidationExpression="[^'^<^>]{0,}"></asp:RegularExpressionValidator>
                    </TD>
                </TR>
                <tr>
                    <td colSpan="2">(支持文件格式:Jpg, Gif, Png)</td>
                </tr>
            </TABLE>
            <table cellSpacing="0" width="750" border="1">
                <tr>
                    <td width="70">图片名称</td>
                    <td width="300"><INPUT title="浏览" type="file" size="25" name="filePicName" runat="server" ID="filePicName">
                        <asp:RegularExpressionValidator id="Regularexpressionvalidator3" Runat="server" CssClass="valid" ErrorMessage="文件名只能由字母或数字组成,不能包含 - _ 等其他符号长度至少为1" ControlToValidate="filePicName" ValidationExpression="[ :./a-zA-Z0-9]{1,}"></asp:RegularExpressionValidator>
                    </td>
                    <td><asp:checkboxlist id="checkboxlistRewrite" runat="server" BorderWidth="0" Height="100%" CellPadding="5" RepeatLayout="Table" RepeatColumns="1" RepeatDirection="Vertical">
                            <asp:ListItem Value="1">覆盖原有图片</asp:ListItem>
                        </asp:checkboxlist></td>
                </tr>
            </table>
            <table cellSpacing="0" width="750" border="1">
                <TR>
                    <TD align="middle"><asp:button id="btnSubmit" onclick="UploadFile" runat="server" Text="确定"></asp:button></TD>
                </TR>
                <TR>
                    <TD><asp:label id="lblPicInfo" runat="server">Label</asp:label></TD>
                </TR>
                <TR>
                    <TD><FONT face="宋体"></FONT>
                    </TD>
                </TR>
            </table>
        </form>
        <asp:HyperLink id="hlkOriPic" runat="server">原图</asp:HyperLink>
        <asp:HyperLink id="hlkNewPic" runat="server">缩略图</asp:HyperLink>
    </body>
</HTML>
axure实现图片上传_通过API接口实现图片上传 通过API接口实现图片上传需求近期在接口功能实现要求,实现一个API图片上传,补充商户开户后补充图片信息,用于管理人员审核.业务要求图片有多条,法人信息,授权信息,等 有必填图片,有非必填图片,文件大小限制为2MB.必填的图片未上,则本次均不录入数据库.图片要求在一次确认后,审核人员才能显示.需要进行相关得记录,用于后续查看.详细设计为了满足以上实现,有两种实现方式单个批量接口 所有的文件通过一... 阅读详情

相关推荐

ASP.NET中图片上传功能的简便实现方法

ASP.NET,作为微软.NET框架的一部分,长期以来一直是企业级Web应用开发的首选技术之一。它是基于公共语言运行时(CLR)构建的,这意味着它可以支持多种编程语言,如C#和VB.NET,为开发者提供了极大的灵活性。ASP.NET核心优势在于其能创建动态网页内容,并可以轻松集成至各种Web服务与应用程序中。ASP.NET的设计初衷是为了简化开发过程。它允许开发者使用声明式编程和基于控件的开发模式,这使得开发动态网站和Web应用程序变得更加高效。

weixin_35749796的博客 1075

SpringBoot简单优雅实现图片上传功能(超详细)

最近有一个需求需要实现图片上传,因此,本人找到了一个可以快速实现该功能的插件mini-upload-form。在此记录分享一下使用过程。mini-upload-form的Github跳转将程序从github拉下后,前端页面index.html可简单修改后直接使用,我们的精力主要放在后端实现。MultipartFile是SpringMVC提供简化上操作的工具类。

BBX__XB的博客 1万+

学习STM32的无人机控制

下面是一个基于STM32的无人机控制的简单示例代码,包括四旋翼的PID控制、遥控器信号解析和电机控制。本示例以STM32F103系列为例,使用Keil C编译器进行开发。

qq_67153941的博客 682

图片上传功能实现

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录前言一、实现思路二、实现代码1.前端代码2.后端代码3.效果总结 前言 实现一下图片上传回显功能。 一、实现思路 大致讲一下思路,具体的细节,会在代码中作注释。前端将图片发送到后端,后端将图片存到服务器,然后返回存储图片的地址到前端,前端通过图片地址回显图片。 二、实现代码 1.前端代码 需要注意的点: 1、上图片的input样式比较固定,所以我决定隐藏input,通过按钮来触发input。隐藏的时候,不能用display:n.

qq_39176307的博客 8465

前端实现图片上传功能的多种方法与实践

一:概述在现代的Web开发中,图片上传功能是许多应用不可或缺的一部分。无论是社交媒体、电商平台还是个人博客,用户都希望能够方便快捷地上图片。本文将详细介绍几种常见的前端图片上传方法,并通过实际案例展示它们的实现过程。二:具体说明一、使用原生HTML表单实现图片上传最简单的方式是利用原生HTML的<input typ...

qq_35485206的博客 3438

图片实现

无论是上图片还是制作各种图表,市场上都有很多第三方控件,而且功能都也做得很不错,当我们需要做这样一个任务时,完全没有必要自己去写一个。我们要学会站在巨人的肩膀上。我们不要想着完全掌握这些第三方控件的使用,大可以理解其中一二,会用就可以了。如果有研究的必要的时候,再深入学习。也就是米老师说的“不怕不知道,就怕不知道”。   现在我整理了一下关于上图片实现思路和代码。主要使用第三方控件:Apa

王雅瑾---上善若水,水善利万物而不争 1381

前端如何实现本地图片上传

前端实现本地图片上传

qq_47828130的博客 3765

Express实现图片上传

首先在node下面下载Express以及multernpm i expressnpm i multer复制代码然后写代码const Express = require("express"); const app = new Express; const fs = require("fs"); const multer = require("multer"); var upload = multer...

weixin_33717117的博客 858

图片上传功能的实现

图片上传功能上一篇中,我们了解了图片上传过程中的预览功能,本篇我们着重实现图片功能,以上图片为例,同样适用于上文件等。

住在城北的猫 1万+

express实现图片上传

常见的前后端交互数据大部分都是json格式的数据,但是当涉及到图片、文件上时,就需要用到form-data格式的数据,以前我们要把input标签的type属性设置为file格式,采用form提交的方式 需要把form的enctype属性设置为multipart/form-data,采用js提交的方式我们就需要手动new一个FormData对象,对其加工处理之后再提交。在javascript已经蔓...

weixin_34407348的博客 6195

图片上传实现

本文介绍了如何使用jQuery的change函数获取输入框值,并详细讲解了图片上传到服务器的实现方法。文章提供了完整的前后端代码示例,在添加和修改页面实现图片上传功能。

2401_84284464的博客 1140

h5 实现图片上传 案例

如何在h5 中实现图片上传 ? (单图片上传) 先写一个按钮 ,通过点击按钮触发文件上的onclick 事件 <div class="btn" onclick="takePhone()">请点击进行拍照</div> <input type="file" name="file" id="upload" capture="camera" onchange="uploadImg()" accept="image/*" value=

Missbelover的博客 4615

vue如何实现图片上传

在服务器端,需要有相应的接口来接收并处理上图片。目录下(你可以根据需要修改保存路径),并且在接口处理函数中可以对上图片进行后续处理,比如将图片的相关信息保存到数据库等。以上就是在Vue中实现图片上传的基本步骤,具体的实现可能会根据项目的实际需求和后端的配合情况进行相应的调整。获取到用户选择的第一个文件(如果允许选择多个文件,可以根据需要进行相应处理),并将其存储在。在Vue组件的模板部分添加一个文件上的表单元素,通常是。中间件来处理文件上,它会将上的文件保存到指定的。

alankuo的专栏 3901

CKEditor实现图片上传

CKEditor实现图片上传

hffygc的博客 9381

vue实现图片上传功能

一、vue的核心插件 vuex vuex用于集中存储管理应用的所有组件的状态(state),在一个项目的开发过程中,如果一些值或者方法被多个组件频繁的使用,就把这些值或者方法定义在vuex中,便于组件的调用。 vue-router 这是一个Vue的官方路由器,让构建单页面应用变得十分简单。 二、服务器代理配置 当向服务器发送请求的时候,可以对请求进行处理后再发送,可以在vue.config.js中进行配置 module.exports = { devServer: { pro

Joy_Huu的博客 4928

struts实现图片上传

struts实现图片上传 文件上: 三种上方案 1、上到tomcat服务器 2、上到指定文件目录,添加服务器与真实目录的映射关系,从而解耦上文件与tomcat的关系 文件服务器 3、在数据库表中建立二进制字段,将图片存储到数据库 课程目标:图片上传以及页面展示 思路: 1、完成功能 今天我们用第2个上方案进行图片上传 下面我们来用代码实现功能 首先我们写一个控制器 这个控制器的功能就...

weixin_45092983的博客 179

Layui框架实现图片上传

Layui框架实现图片上传 前言: 一直以来,图片上传总是件很麻烦的事。最近在学layui,发现layui真是极大简化了各种复杂的操作,避免了繁琐的开发。 layui图片上传统的图片上传不同,它并不予表单元素并存,而是单独通过异步来上到后端,继而进行之后的操作。所以,编写表单代码时,并不需要添加enctype=“multipart/form-data” 和 ==input type=“fil...

红烧大熊猫的博客 3万+
上一篇: c#.net函数列表
下一篇: 动态加载用户控件的组件
Awinye
博客等级 码龄21年 13粉丝 122原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值