当前位置: 首页 > news >正文

基于React + Antd + Java的OFD文件上传预览实现方案(OFD文件转图片)

一、前端实现方案(React + Antd)

import React, {
    useState } from 'react';
import {
    Upload, Button, Image, Carousel } from 'antd';
import {
    UploadOutlined } from '@ant-design/icons';
 
const OFDUploadPreview = () => {
   
  const [previewImages, setPreviewImages] = useState([]);
 
  // 自定义上传方法 
  const customRequest = async ({
     file, onSuccess }) => {
   
    const formData = new FormData();
    formData.append('file',  file);
    
    try {
   
      const response = await fetch('http://localhost:8080/convert-ofd',  {
   
        method: 'POST',
        body: formData 
      });
      
      const result = await response.json(); 
      if (result.success)  {
   
        setPreviewImages(result.images);  // 接收转换后的图片数组 
        onSuccess(result, file);
      }
    } catch (error) {
   
      console.error('Upload  failed:', error);
    }
  };
 
  return (
    <div style={
   {
    padding: 24 }}>
      <Upload 
        customRequest={
   customRequest}
        accept=".ofd"
        showUploadList={
   false}
      >
        <Button icon={
   <UploadOutlined />}>上传OFD文件</Button>
      </Upload>
 
      {
   /* 多页预览 */}
      {
   previewImages.length  > 0 && (
        <div style={
   {
    marginTop: 20 }}>
          <Carousel dotPosition="top">
            {
   previewImages.map((img,  index) => (
              <div key={
   index}>
                <Image 
                  src={
   `data:image/png;base64,${
     img}`}
                  alt={
   `Page ${
     index + 1}`}
                  style={
   {
    maxWidth
http://www.dtcms.com/a/107007.html

相关文章:

  • 删除和关闭 Solana 中的账户和程序
  • Linux网络相关概念和重要知识(4)(序列化和反序列化、TCP协议、会话和守护进程)
  • 基于OpenCV的指纹验证:从原理到实战的深度解析
  • vue3 动态路由
  • 第1章-3 MySQL的逻辑架构
  • 【C++】二叉搜索树
  • 【哈希表】—— 我与C++的不解之缘(二十八)
  • [CISSP] [4] 法律、法规
  • alfred-deepseek开源程序在 Alfred 中与 DeepSeek 聊天
  • [IOI 2000] 回文字串
  • 符号秩检验
  • 跟着尚硅谷学vue-day2
  • 23 种设计模式中的解释器模式
  • C++友元与动态内存
  • 关于存储的笔记
  • go语言:开发一个最简单的用户登录界面
  • 剑指Offer(数据结构与算法面试题精讲)C++版——day3
  • 【数据结构】树、森林与二叉树的转换(含详细图解)
  • TypeScript 泛型与 keyof 约束 | 深入解析
  • 钉钉 + AI 网关给 DeepSeek 办入职
  • Photoshop 2025 Mac中文 Ps图像编辑软件
  • 陈关荣 | 明清江南数学家
  • Cursor助力Java开发(快捷键+配置篇)
  • nginx的反向代理和负载均衡
  • git分布式控制工具详解
  • 深入解析使用Python通过STOMP协议接收ActiveMQ消息
  • 数据库6(数据库指令)
  • Django 使用 matplotlib 遇到 RuntimeError: main thread is not in main loop 解决办法
  • Linux系统程序设计:从入门到高级Day01
  • NHANES指标推荐:HCHR