• webapi接收post数据


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Http;
    using Microsoft.AspNetCore.Mvc;
    using System.Web;
    using System.IO;
    namespace swaggerTest1.Controllers
    {
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class OrderController : ControllerBase
    {
    [HttpGet]
    public string OrderSingle()
    {
    return "测试1";
    }
    [HttpGet]
    public string OrderList()
    {
    return "订单列表";
    }

    [HttpPost]
    public string Upload(UserInfo model)
    {
    //https://localhost:44303/api/Order/Upload
    //{"username":"小五","ZhaiyaoUrl":"23123","QuanwenUrl":"666"}
    string dir = AppDomain.CurrentDomain.BaseDirectory;
    //使用path获取当前应用程序集的执行的上级目录
    dir = Path.GetFullPath("..");
    //使用path获取当前应用程序集的执行目录的上级的上级目录
    dir = Path.GetFullPath("../../../xiaowutemp/");

    if(!Directory.Exists(dir))
    {
    Directory.CreateDirectory(dir);
    }

    string username = model.userName;
    string ZhaiyaoUrl = model.ZhaiyaoUrl;
    string QuanwenUrl = model.ZhaiyaoUrl;
    string quanWenpath = dir + DateTime.Now.ToString("yyyyMMddHHmmss")+"全文.doc" ;
    string zhaiyaoPath = dir + DateTime.Now.ToString("yyyyMMddHHmmss") + "摘要.doc";
    byte[] quanwenByte =Convert.FromBase64String(QuanwenUrl);
    byte[] zhaiyaoByte = Convert.FromBase64String(ZhaiyaoUrl);


    Bytes2File(zhaiyaoByte, zhaiyaoPath);

    Bytes2File(quanwenByte, quanWenpath);
    string res = "success";
    return res;
    }


    /// <summary>
    /// 将byte数组转换为文件并保存到指定地址
    /// </summary>
    /// <param name="buff">byte数组</param>
    /// <param name="savepath">保存地址</param>
    public static void Bytes2File(byte[] buff, string savepath)
    {
    if (System.IO.File.Exists(savepath))
    {
    System.IO.File.Delete(savepath);
    }
    FileStream fs = new FileStream(savepath, FileMode.CreateNew);
    BinaryWriter bw = new BinaryWriter(fs);
    bw.Write(buff, 0, buff.Length);
    bw.Close();
    fs.Close();
    }

    public class UserInfo {

    public string userName { get; set; }

    public string ZhaiyaoUrl { get; set; }

    public string QuanwenUrl { get; set; }
    }
    }
    }

  • 相关阅读:
    关于中间件(Middleware)的理解
    强类型约束的中间件(IMiddleware)
    常规中间件(Conventional Middleware) 之 自定义中间件
    常规中间件(Conventional Middleware) 之 内联中间件(in-line middleware)
    git 遴选(cherry-pick)
    sql转linq
    python知识体系
    when 的使用
    关于联表查询时NULL值的处理
    $project 选择要显示的字段
  • 原文地址:https://www.cnblogs.com/wugh8726254/p/14752732.html
Copyright © 2020-2023  润新知