zoukankan      html  css  js  c++  java
  • 以调用接口的方式将文件上传至Web服务器

     前台代码:

    <form id="form1" action="http://www.abc.com/data/UploadFile.aspx" method="post" enctype="multipart/form-data" >
      <input type="file" name="F" style="160px;" />
      <input type="submit" name="Submit" value="提交" />
    </form>

    (浏览器本身就是个APP,用户点击提交按钮后,浏览器会以Post方式调用文件上传接口;

    给APP提供文件上传接口和这类似,APP那边的文件上传程序只需要设置好相应的Http请求参数,比如上面的name="F",请求地址和请求方式等,就可以将文件传到服务器)

    后台代码:

    HttpPostedFile file = Request.Files["F"];

    string filename = System.IO.Path.GetFileName(file.FileName); 

    file.SaveAs(Server.MapPath(filename));

    如果是上传图片文件,前台程序可以先将图片转成Base64字符串,后端接口程序再把接收到的Base64字符串转成图片,比如:

    string f = HttpContext.Current.Request["F"]; //与上面的方式不同,此时的F对于前台程序来说是普通的参数

    MemoryStream ms = new MemoryStream(Convert.FromBase64String(f));

    Bitmap bmp = new Bitmap(ms);

    bmp.Save(HttpContext.Current.Server.MapPath("f.jpg"), System.Drawing.Imaging.ImageFormat.Jpeg);

  • 相关阅读:
    php 注册与登录
    php 多条件查询
    php(ajax)异步刷新(转)
    PHP中的6种加密方式
    ajax 异步刷新,需要填写的参数
    php+Mysql 页面登录代码
    php+Mysql页面注册代码
    jquery入门知识点总结(转)
    php+Mysql中网页出现乱码的解决办法详解
    php代码常见错误详解整理
  • 原文地址:https://www.cnblogs.com/Arlar/p/5934938.html
Copyright © 2011-2022 走看看