惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
宝玉的分享
宝玉的分享
The Cloudflare Blog
Apple Machine Learning Research
Apple Machine Learning Research
V
Visual Studio Blog
Last Week in AI
Last Week in AI
Hugging Face - Blog
Hugging Face - Blog
博客园 - 司徒正美
博客园 - 三生石上(FineUI控件)
A
About on SuperTechFans
MyScale Blog
MyScale Blog
aimingoo的专栏
aimingoo的专栏
Microsoft Security Blog
Microsoft Security Blog
D
Docker
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Recent Announcements
Recent Announcements
大猫的无限游戏
大猫的无限游戏
IT之家
IT之家
P
Proofpoint News Feed
L
LangChain Blog
Blog — PlanetScale
Blog — PlanetScale
The GitHub Blog
The GitHub Blog
博客园 - 【当耐特】
Martin Fowler
Martin Fowler

博客园 - Insus.NET

Vue3实现拖放式上传 拖放式上传 实现MultipartStreamProvider经Web API上传文档或图片 在HttpContext.Current返回null时如何操作 angularjs根据类型动态加载组件 angularjs获取数据服务 扫一扫直连WiFi二维码 User Profile Service 服务未能登录 Visual Studio2026创建Vue项目 安装与配置node.js HTTP Error 403.14 - Forbidden VisualStudio2026回滚上一版本 消息认证码(加强) 网站无法使用插值字符串语法 HMAC(Hash-based Message Authentication Code)认证示例 浏览器自动发送域凭据 企业内小网站兼用Windows验证登录 访问用户控件的函数 onblur事件改为监听处理 将警报消息改为吐司消息 内容有无变化OnBlur即时更新引起的问题与解决 混合式提高用户编辑与操作效率 光标离开文框后即刻更新 WebForm实现Web API JavaScript对GridView删除行后并重新给其数据绑定 把CS值传给JS使用 v2 确认信息confirm由C#后端移至javascript前端 无法发布网站Web Site JavaScript判断字符是否为decimal 点击单元格弹出窗口处理数据返回父页
文件上传和表单字段混合提交
Insus.NET · 2026-09-10 · via 博客园 - Insus.NET

Insus.NET根据实际需求,在用户填写表单和上传文档一次性处理,即是说文件上传和表单字段混合提交,在内存中处理上传的内容。

参考MultipartFormDataStreamProviderhttps://learn.microsoft.com/en-us/previous-versions/aspnet/hh835949(v=vs.118) 【此链接不再定期更新内容】
2026-09-09_06-04-48

 
Web API File Upload, Single or Multiple files https://damienbod.com/2014/03/28/web-api-file-upload-single-or-multiple-files/

 
还可以参考相关详细:
https://github.com/aspnet/AspNetWebStack/tree/main/src/System.Net.Http.Formatting

从上面知识点,创建适合自己使用的类,
2026-09-10_05-49-15

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using System.Web;

/// <summary>
/// InsusNetMultipartFormDataStreamProvider 的摘要说明
/// </summary>
namespace Insus.NET
{
    public class InsusNetMultipartFormDataStreamProvider : MultipartStreamProvider
    {
        private NameValueCollection _formData = new NameValueCollection();

        private List<HttpContent> _fileContents = new List<HttpContent>();

        private Collection<bool> _isFormData = new Collection<bool>();

        public NameValueCollection FormData
        {
            get { return _formData; }
        }

        public List<HttpContent> Files
        {
            get { return _fileContents; }
        }

        public override Stream GetStream(HttpContent parent, HttpContentHeaders headers)
        {
            ContentDispositionHeaderValue contentDisposition = headers.ContentDisposition;
            if (contentDisposition != null)
            {
                _isFormData.Add(String.IsNullOrEmpty(contentDisposition.FileName));

                return new MemoryStream();
            }

            throw new InvalidOperationException(string.Format("Did not find required '{0}' header field in MIME multipart body part..", "Content-Disposition"));
        }

        public override async Task ExecutePostProcessingAsync()
        {
            for (int index = 0; index < Contents.Count; index++)
            {
                if (_isFormData[index])
                {
                    HttpContent formContent = Contents[index];
                    ContentDispositionHeaderValue contentDisposition = formContent.Headers.ContentDisposition;

                    string formFieldName = UnquoteToken(contentDisposition.Name) ?? String.Empty;

                    string formFieldValue = await formContent.ReadAsStringAsync();


                    FormData.Add(formFieldName, formFieldValue);
                }
                else
                {
                    _fileContents.Add(Contents[index]);
                }
            }
        }

        private static string UnquoteToken(string token)
        {
            if (String.IsNullOrWhiteSpace(token))
            {
                return token;
            }

            if (token.StartsWith("\"", StringComparison.Ordinal) && token.EndsWith("\"", StringComparison.Ordinal) && token.Length > 1)
            {
                return token.Substring(1, token.Length - 2);
            }

            return token;
        }
    }
}

View Code

后续博文中,会有相关实例分享...