@Test
public void testUpload() throws Exception {
String url = "http://127.0.0.1/file/upload";
String filePath = "C:\\temp\\1.png"; RestTemplate rest = new RestTemplate();
FileSystemResource resource = new FileSystemResource(new File(filePath));
MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
param.add("file", resource);
param.add("fid", "1"); String string = rest.postForObject(url, param, String.class); System.out.println(string);
}

或者

    @Test
public void testUpload2() throws Exception { String url = "http://127.0.0.1/file/upload";
String filePath = "C:\\temp\\1.png"; RestTemplate rest = new RestTemplate();
FileSystemResource resource = new FileSystemResource(new File(filePath));
MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
param.add("file", resource);
param.add("fid", "1"); HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<MultiValueMap<String, Object>>(param);
ResponseEntity<String> responseEntity = rest.exchange(url, HttpMethod.POST, httpEntity, String.class); System.out.println(responseEntity.getBody()); }

SpringBoot项目 前后端分离 ajax附件上传下载,参考SpringBoot项目 前后端分离 ajax附件上传下载

SpringBoot RestTemplate 上传文件的更多相关文章

  1. Spring Boot 上传文件 获取项目根路径 物理地址 resttemplate上传文件

    springboot部署之后无法获取项目目录的问题: 之前看到网上有提问在开发一个springboot的项目时,在项目部署的时候遇到一个问题:就是我将项目导出为jar包,然后用java -jar 运行 ...

  2. 通过`RestTemplate`上传文件(InputStreamResource详解)

    通过RestTemplate上传文件 1.上传文件File 碰到一个需求,在代码中通过HTTP方式做一个验证的请求,请求的参数包含了文件类型.想想其实很简单,直接使用定义好的MultiValueMap ...

  3. SpringBoot初探(上传文件)

    学了Spring,SpringMVC,Mybatis这一套再来看SpringBoot,心里只有一句握草,好方便 这里对今天做的东西做个总结,然后在这之间先安利一个热部署的工具,叫spring-DevT ...

  4. Springboot实现上传文件接口,使用python的requests进行组装报文上传文件的方法

    记录瞬间 近段时间使用Springboot实现了文件的上传服务,但是在使用python的requests进行post上传时,总是报错. 比如: 1.Current request is not a m ...

  5. RestTemplate上传文件

    1.上传的文件是File类型 如果文件保存在本地,即可以通过File file = new File(path) 或者 文件路径地址获取到指定文件 public String uploadFile(F ...

  6. springboot项目上传文件出现临时文件目录为空

    最近写文件上传到服务器读取的代码,前端使用FormData上传,服务端用MultipartFile接收,自己测试了下MultipartFile对象有什么东西,结果一般属性都能出来,测试getInput ...

  7. 使用RestTemplate上传文件给远程接口

    MultiValueMap request = new LinkedMultiValueMap(1); ByteArrayResource is = new ByteArrayResource(mul ...

  8. springboot +fastdfs 上传文件到到云服务器

    fastdfs在云服务器的搭建和配置:https://blog.csdn.net/qq_41592652/article/details/104006289 springboot结构如下: appli ...

  9. 二、SpringBoot实现上传文件到fastDFS文件服务器

    上篇文章介绍了如何使用docker安装fastDFS文件服务器,这一篇就介绍整合springBoot实现文件上传到fastDFS文件服务器 1.pom.xml文件添加依赖 <!-- 连接fast ...

  10. springboot 头像上传 文件流保存 文件流返回浏览器查看 区分操作系统 windows 7 or linux

    //我的会员中心 头像上传接口 /*windows 调试*/ @Value("${appImg.location}") private String winPathPic; /*l ...

随机推荐

  1. 【Unity3D】顶点和片元着色器

    1 前言 ​ 上文介绍了渲染管线.固定管线着色器和表面着色器,如下: 渲染管线 固定管线着色器一 固定管线着色器二 表面着色器 ​ 固定管线着色器通过命令方式实现光照和贴图等效果,表面着色器通过给 S ...

  2. nginx实战笔记

    1.添加一个虚拟机 /usr/local/nginx/sbin ./nginx -t nginx: [warn] conflicting server name "localhost&quo ...

  3. win32 - ReadDirectoryChangesW的使用

    任务:创建一个进程,并在进程内创建一个文本,再创建另一个进程来监控第一个进程内的文本变化 //Process 1 #include <windows.h> #include <ios ...

  4. Vue3学习(十八) - TreeSelect 树选择

    写在前面 本以为可以在家学习一天,结果家里来了客人拜年,就没学习上,有点小遗憾吧. 昨天完成从分类管理的前后端代码复制出文档管理的前后端代码,遗留问题是只能选择一级父分类.值得说的是,昨晚的遗留的问题 ...

  5. MongoDB的安装及启动

    下载地址 https://www.mongodb.com/try/download/community 安装步骤 自定义安装目录 配置环境 下面是你安装后的mongodb的目录 在电脑的环境变量Pat ...

  6. core-js/modules/es7.arrat......................报错

    拉入代码之后出现如图提示,导致原因是因为core-js版本太高,可以用cnpm install core-js@2成功解决,安装一个项目前最后将node-moudel删除,重新安装

  7. STL-RBTree模拟实现

    #pragma once #include<assert.h> #include<iostream> using std::cout; using std::endl; usi ...

  8. [逆向] PE文件学习

    目录 概述 MS-DOS 头部 IMAGE_DOS_HEADER PE头 IMAGE_NT_HEADER IMAGE_FILE_HEADER IMAGE_OPTIONAL_HEADER32 数据目录列 ...

  9. Java 常用类 String类与其他结构之间的转换-----String 与 byte[]之间的转换

    1 /** 2 * 3 * String 与 byte[]之间的转换 4 * 编码:String ---> byte[]:调用String的getBytes() 5 * 解码:byte[]--- ...

  10. Mutillidae品台上使用sqlmap注入测试

    Mutillidae是一个开放源码的提供安全渗透测试的Web应用程序, Mutillidae可以安装在Linux.windows xp.windows 7等平台上.下载及安装说明文档详见:mutill ...