如何在 Postman 中上传文件和 JSON 数据?

编程入门 行业动态 更新时间:2024-10-25 16:30:20
本文介绍了如何在 Postman 中上传文件和 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?

推荐答案

在postman中,设置方法类型为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.

更多推荐

如何在 Postman 中上传文件和 JSON 数据?

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

发布评论

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

>www.elefans.com

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