Tag: file upload

在REST方法调用上上载的文件已损坏

所以我在我的Web应用程序中使用以下Rest方法来上传文件。 当我上传文本文件时,它们会正确保存,我可以打开它们。 但是在任何其他格式(即* .docx或* .pdf或* .jpg)的情况下,文件的存储大小与原始文件完全相同但已损坏。 以下是代码: @POST @Consumes(“multipart/form-data”) public Response readFile() throws IOException, ServletException { Part filePart = request.getPart(“c”); InputStream f = filePart.getInputStream(); String l = null; DataInputStream ds = new DataInputStream(f); File file = new File(“c:\\temp\\” + getSubmittedFileName(filePart)); try { BufferedWriter bw = new BufferedWriter(new FileWriter(file)); while ((l = ds.readLine()) != null) { […]

使用MultipartFile在Spring Boot中无法上传多个文件,从JSP中获取Controller中的空数组

我正在使用MultipartFile上传多个文件。 但是当我从Jsp页面选择多个文件并单击提交时,我在控制器中得到空数组。 这是我的代码片段, 在pom.xml中 commons-fileupload commons-fileupload 1.3.3 CommonsMultipartResolver Bean配置。 @Bean public CommonsMultipartResolver multipartResolver() { CommonsMultipartResolver resolver=new CommonsMultipartResolver(); resolver.setDefaultEncoding(“utf-8”); resolver.setMaxUploadSize(999999999); return resolver; } JSP代码 Select User ${user.userName} 控制器代码 @PostMapping(value = “/createRequest”) public ModelAndView createRequest(@RequestParam(“fileUpload”) MultipartFile[] fileUpload, @RequestParam(“userDirectory”) String userDirectory) throws IOException { log.info(“In createRequest method”); if (fileUpload != null && fileUpload.length > 0) { Flow not […]

使用HttpClient上传video文件

我正在构建Java客户端,它将自动将文件从Java服务器上传到我使用他们的AMI安装在我的EC2云上的Panda Instance。 我正在尝试使用Apache HTTP Components上传到Panda Server( Panda Stream )。 它适用于我的浏览器客户端但由于某种原因我无法从该库上传。 这是我的代码: String videoUploadUrl = “http://[panda server ip]/videos/” + getVideoID() + “/upload.xml”; File file = new File(“/temp/videofile.mp4”); DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); HttpPost httppost = new HttpPost(videoUploadUrl); MultipartEntity mpEntity = new MultipartEntity(); ContentBody fBody = new FileBody(file); mpEntity.addPart(“userfile”, fBody); httppost.setEntity(mpEntity); System.out.println(“executing request ” + […]

如何限制java servlet中的上传速度?

我正在开发一个应用程序(基于Spring作为DI和MVC框架),它具有文件上传function,目前使用Spring Multipart Upload(它使用commons fileupload libs)实现。 所以我正在寻找的是一种降低上传带宽消耗的方法。 我怎么能做到这一点?

将照片上传到OpenShift。 Spring MVC

我在OpenShift服务器上部署了我的Spring MVC应用程序的.war文件。 每个用户都可以更改照片。 它适用于我的localhost,但我需要在OpenShift服务器上传照片并将每张照片的路径放到数据库中。 这是我上传文件的方法 @RequestMapping(value = “/user/updateinfo”, method = RequestMethod.POST) public String postAvatar(@RequestParam(“file”) MultipartFile file, Principal principal) { if (file.isEmpty()) { return “redirect:/user”; } if (!file.isEmpty()) { try { String relativeWebPath = “/resources/avatars/”; String absoluteFilePath = context.getRealPath(relativeWebPath); String name = file.getOriginalFilename(); // String name=file.getOriginalFilename(); System.out.println(absoluteFilePath); String path = absoluteFilePath + “/” + name; File […]

新上传的文件和Tomcat?

我有一个简单的servlet用于图像上传,用户选择一个图像,servlet完成其工作,然后将其写入上传目录。 我的项目布局: project ├───static │ ├───img │ └───js ├───upload └───WEB-INF └───lib 上传图像后,用户将被重定向到其位置: http://localhost:8080/upload/[image MD5 hash].png 上传代码工作得很好,但是在请求url时Tomcat返回404错误,即使图像在那里: > wget http://localhost:8080/upload/f5d1da2cadf3bd1c1b9196ec522a5d73.png SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc syswgetrc = C:\GnuWin32/etc/wgetrc –2013-01-16 03:45:33– http://localhost:8080/upload/f5d1da2cadf3bd1c1b9196ec522a5d73.png Resolving localhost… 127.0.0.1, ::1 Connecting to localhost|127.0.0.1|:8080… connected. HTTP request sent, awaiting response… 404 Not Found 2013-01-16 03:45:33 ERROR 404: Not Found. > 在我的IDE,Intellij中单击update classes and resources后,它可以工作: […]

Spring File Upload内部服务器错误

我正在尝试使用spring mvc上传文件。 我的表格: Name: Email ID: Attachment: Submit?: 我收到内部服务器错误。 错误是: 1)505错误 2)没有堆栈跟踪 表单重置自己而不是转到下一页,这是一个通知页面。

在struts1中上传文件

我想在struts1应用程序中上传一个文件。 目前实现使用File,如下所示: 但是,如果从远程计算机访问应用程序,则不允许上载文件,因为此窗口小部件仅传递文件的名称而不是整个文件。

没有struts标签的struts 2文件上传

我是否需要使用struts标签 使用struts 2提供的文件上传function? 没有struts 2标签,我可以实现相同的function吗? 如果是,我是否可以知道需要将约定纳入操作或配置文件中以实现相同的目的?

Spring MVC Error 405上传文件时不支持请求方法’POST’

我想我已经看到网上关于这个主题的每一篇文章,但我无法纠正这个错误:( 我有一个使用Spring Security和Spring Mvc的Web应用程序,我想创建一个表单来上传图像(你必须记录下来才能这样做)但是无论我用我在论坛上找到的代码扭曲我的代码,我都有一个错误405上载文件时不支持请求方法“POST” 这是我的applicationContext.xml: 我的控制器: @Controller public class FileUploadController { @RequestMapping(value=”/bo/uploadImage”, method = RequestMethod.GET) public String uploadImage() { return “bo_uploadimage”; } @RequestMapping(value=”/bo/uploadImage”, method = RequestMethod.POST) public String uploadImage(@RequestParam(value = “file”)FileUploadBean file, BindException errors, Map model) { System.out.println(“#############################” + file); return “bo_uploadimage”; } } public class FileUploadBean{ private byte[] file; public void setFile(byte[] file) { […]