如何在邮递员中上传文件和json数据

编程入门 行业动态 更新时间:2024-10-25 18:24:52
本文介绍了如何在邮递员中上传文件和json数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用Spring MVC,这是我的方法:

I am using Spring MVC and this is my method:

/** * Upload single file using Spring Controller */ @RequestMapping(value = "/uploadFile", method = RequestMethod.POST) public @ResponseBody ResponseEntity<GenericResponseVO<? extends IServiceVO>> uploadFileHandler(@RequestParam("name") String name, @RequestParam("file") MultipartFile file,HttpServletRequest request, HttpServletResponse response) { if (!file.isEmpty()) { try { byte[] bytes = file.getBytes(); // Creating the directory to store file String rootPath = System.getProperty("catalina.home"); File dir = new File(rootPath + File.separator + "tmpFiles"); if (!dir.exists()) dir.mkdirs(); // Create the file on server File serverFile = new File(dir.getAbsolutePath() + File.separator + name); BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(serverFile)); stream.write(bytes); stream.close(); System.out.println("Server File Location=" + serverFile.getAbsolutePath()); return null; } catch (Exception e) { return null; } } }

我需要在邮递员和文件中传递会话ID.我该怎么办?

I need to pass the session id in postman and also the file. How can I do that?

推荐答案

在邮递员中,将方法类型设置为 POST .

In postman, set method type to POST.

然后选择 正文->表单数据->输入您的参数名称(根据您的代码文件)

Then select Body -> form-data -> Enter your parameter name (file according to your code)

在值列旁边的右侧,将出现下拉文本,文件" ,然后选择文件.选择您的图片文件并将其发布.

and on right side next to value column, there will be dropdown "text, file", select File. choose your image file and post it.

对于其余基于文本"的参数,您可以像平常对邮递员一样进行发布.只需输入参数名称,然后从右侧的下拉菜单中选择文本",然后为其输入任何值,请点击发送按钮.您的控制器方法应该被调用.

For rest of "text" based parameters, you can post it like normally you do with postman. Just enter parameter name and select "text" from that right side dropdown menu and enter any value for it, hit send button. Your controller method should get called.

更多推荐

如何在邮递员中上传文件和json数据

本文发布于:2023-10-29 04:10:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1538683.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:邮递员   上传文件   数据   如何在   json

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!