qw-33

news/2025/10/31 2:34:39/文章来源:https://www.cnblogs.com/lihuadaiyu/p/19178487
import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.netty.http.client.HttpClient; import reactor.netty.http.client.HttpClientResponse; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; // 或 HSSFWorkbook import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.UUID; public class ExcelUploader { public static Mono<HttpClientResponse> uploadExcel( Workbook workbook, String originalFilename, String uploadUrl) { // Step 1: 将 Workbook 写入 byte[] byte[] excelBytes; try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { workbook.write(baos); excelBytes = baos.toByteArray(); } catch (IOException e) { return Mono.error(new RuntimeException("Failed to serialize workbook", e)); } // Step 2: 构建 multipart/form-data body String boundary = "----ReactorNettyBoundary" + UUID.randomUUID().toString(); String contentType = "multipart/form-data; boundary=" + boundary; Flux<ByteBuf> body = createMultipartData(boundary, excelBytes, originalFilename); // Step 3: 发送 POST 请求 return HttpClient.create() .post() .uri(uploadUrl) .header("Content-Type", contentType) .send(body) .response(); // 返回响应,可进一步处理 } private static Flux<ByteBuf> createMultipartData(String boundary, byte[] fileBytes, String filename) { String crlf = "\r\n"; String twoHyphens = "--"; // Part 1: 文件头 String fileHeader = twoHyphens + boundary + crlf + "Content-Disposition: form-data; name=\"file\"; filename=\"" + filename + "\"" + crlf + "Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" + crlf + crlf; // Part 2: 文件尾 String footer = crlf + twoHyphens + boundary + twoHyphens + crlf; return Flux.concat( // 文件头(文本) Flux.just(fileHeader) .map(s -> Unpooled.wrappedBuffer(s.getBytes(StandardCharsets.UTF_8))), // 文件内容(二进制) Flux.just(Unpooled.wrappedBuffer(fileBytes)), // 结尾 Flux.just(footer) .map(s -> Unpooled.wrappedBuffer(s.getBytes(StandardCharsets.UTF_8))) ); } }

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/951254.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

qw-12

import org.springframework.core.io.ByteArrayResource;import org.springframework.core.io.buffer.DataBuffer;import org.springframework.core.io.buffer.DataBufferUtils;import org.springframework.http.Media…

reactive -03

import org.springframework.core.io.buffer.DataBuffer;import org.springframework.core.io.buffer.DataBufferUtils;import org.springframework.http.codec.multipart.FilePart;import org.springframework.web.re…

reactive - 02

import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.web.reactive.function.BodyInserters;import org.springfra…

reactive-01

package com.hyman.service; import org.springframework.core.io.ByteArrayResource;import org.springframework.core.io.buffer.DataBufferUtils;import org.springframework.http.HttpHeaders;import org.springfr…

revit api获取excursion 拉伸体的轮廓和平面sketchplane GeometryCreationUtilities

revit api获取excursion 拉伸体的轮廓和平面sketchplane GeometryCreationUtilitiespublic void GetSketchFromExtrusion() {Document doc = this.ActiveUIDocument.Document;Extrusion extrusion = doc.GetEleme…

revit api创建模型线

revit api创建模型线public void CreateModelCurve() {Document doc = this.ActiveUIDocument.Document; // 在族文档中找到名字为"Ref. Level"的标高FilteredElementCollector collector = new Filtered…

revit 创建sketchplane

revit 创建sketchplanesketchplane在创建某些图元时候可以用到 public void CreateSketchPlaneByPlane() {Document doc = this.ActiveUIDocument.Document; using(Transaction trans = new Transaction(doc, "…

revit api创建参考线

revit api创建参考线参考线可以用modelcurve转化而来 public void ChangeModelCurveToReferenceLine() { Document doc = this.ActiveUIDocument.Document; ModelCurve modelCurve = doc.GetElement(new…

【AI说HTML 04】掌握核心文档结构标签的方法

要真正掌握HTML的核心文档结构标签,关键在于理解它们如何像搭积木一样,共同构建起一个清晰、语义明确的网页骨架。下面这个流程图概括了一个网页的典型结构,帮你先建立整体印象: flowchart TDA[<!DOCTYPE html&…

revit api创建参考平面

revit api创建参考平面public void CreatReferencePlane() {Document doc = this.ActiveUIDocument.Document; if(!doc.IsFamilyDocument)return;using(Transaction transaction = new Transaction(doc, "Edit…

【AI说HTML 02】如何深刻建立对HTML的正确认知

要深刻建立对HTML的正确认知,关键在于理解它不仅仅是用来“画”出网页样子的工具,更是一套用于描述内容结构和含义的语言。下面这个表格梳理了理解HTML时需要建立的核心认知维度。认知维度 错误认知(新手常见) 正确…

【AI说HTML 03】手把手教你搭建极简HTML开发环境

为你打造一个极简且高效的HTML开发环境,其实只需要几个核心步骤。下面这张流程图概括了全过程,你可以先有一个整体的了解,再跟着后续的详细步骤操作。 flowchart TDA[下载并安装VS Code] --> B[安装必备插件<…

图元编辑 移动 旋转 镜像等

图元编辑 移动 旋转 镜像等编辑1 Document projectDoc = ActiveUIDocument.Document;using(Transaction moveColumnTran = new Transaction(projectDoc, "Move a new column to the new place")) {moveCol…

【AI说】如何深刻建立对HTML的正确认知

要深刻建立对HTML的正确认知,关键在于理解它不仅仅是用来“画”出网页样子的工具,更是一套用于描述内容结构和含义的语言。下面这个表格梳理了理解HTML时需要建立的核心认知维度。认知维度 错误认知(新手常见) 正确…

计算机组成原理核心知识点梳理

SQLAlchemy是Python中最流行的ORM(对象关系映射)框架之一,它提供了高效且灵活的数据库操作方式。本文将介绍如何使用SQLAlchemy ORM进行数据库操作。 目录 安装SQLAlchemy 核心概念 连接数据库 定义数据模型 创建数…

revit api 内置族类型 walltype

revit api 内置族类型 walltype复制墙类型 Wall wall = RevitDoc.GetElement(new ElementId(185521)) as Wall; WallType wallType = wall.WallType; ElementType duplicatedWallType = wallType.Duplicate(wallType.…

国产的编程语言

​1、非修改序列算法 这些算法不会改变它们所操作的容器中的元素。 1.1 find 和 find_if find(begin, end, value):查找第一个等于 value 的元素,返回迭代器(未找到返回 end)。 find_if(begin, end, predicate):查…

revit api族文件图元编辑 familyitem factory

revit api族文件图元编辑 familyitem factory创建拉伸实体 //创建族文档 Document familyDoc = RevitApp.NewFamilyDocument(@"C:\ProgramData\Autodesk\RVT 2014\Family Templates\Chinese\公制常规模型.rft&qu…

【AI说】HTML从零基础到精通路径

学习HTML从零基础到精通,是一个循序渐进的过程,关键在于建立正确的认知、通过实践巩固知识,并逐步关注更宏观的网页质量维度。下面我为你梳理一条清晰的路径,并附上每个阶段的学习重点和建议。 为了让你对整体学习…