Tag: file upload

Spring MVC – 上传文件被spring security 阻止

我正在尝试上传文件。 它适用于我,但如果我想使用上传文件它不起作用。 我收到了这个错误 HTTP Status 405 – Request method ‘POST’ not supported 但是,如果我在web.xml中对这些行进行注释,它可以工作 springSecurityFilterChain org.springframework.web.filter.DelegatingFilterProxy springSecurityFilterChain /* 我试图添加此配置,但它没有帮助 springMultipartFilter springMultipartFilter org.springframework.web.multipart.support.MultipartFilter springMultipartFilter /* 这是我的所有web.xml contextConfigLocation /WEB-INF/spring/root-context.xml, /WEB-INF/spring-security.xml org.springframework.web.context.ContextLoaderListener appServlet org.springframework.web.servlet.DispatcherServlet contextConfigLocation /WEB-INF/spring/appServlet/servlet-context.xml 1 appServlet / encodingFilter org.springframework.web.filter.CharacterEncodingFilter encoding UTF-8 forceEncoding true encodingFilter / springMultipartFilter springMultipartFilter org.springframework.web.multipart.support.MultipartFilter springSecurityFilterChain org.springframework.web.filter.DelegatingFilterProxy springMultipartFilter /* springSecurityFilterChain /* 你知道哪里可能有问题吗? 我正在使用这些版本的弹簧和弹簧安全性: 4.0.4.RELEASE […]

如何在HttpRequest中获取源文件以上传文件

我在使用java的REST Web服务中上传文件时遇到问题。 我不知道如何获取源文件。 curl命令就是这样 curl –upload-file /home/student1/text1.txt http:// localhost:20260 / project / resources / user1 / sub-folder / text1.txt 我的问题是,任何人都知道如何在REST Web服务@PUT方法中获取源文件URL“/home/student1/text1.txt”?还是任何其他方式来获取它? 谢谢

Resteasy和fileupload:没有内容处理错误

我有一个可以上传文件的rest资源。 @Path(“/rest/input”) public class InputResourceBean { @POST @Path(“{directory: .*}”) @Consumes(“multipart/form-data”) public void post(final String directory, final MultipartFormDataInput input) { } 我已经使用SOAPUI,curl和HTML表单来测试这段代码,并且对于所有这些代码我都得到了同样的错误:在部分内部找不到Content-Disposition标头 12:55:19,739 WARN [org.jboss.resteasy.core.SynchronousDispatcher] Failed executing POST /rest/input/myDir: org.jboss.resteasy.spi.ReaderException: java.lang.RuntimeException: Could find no Content-Disposition header within part at org.jboss.resteasy.core.messagebody.ReaderUtility.doRead(ReaderUtility.java:123) [:6.0.0.Final] at org.jboss.resteasy.core.messagebody.ReaderUtility.doRead(ReaderUtility.java:93) [:6.0.0.Final] at org.jboss.resteasy.core.MessageBodyParameterInjector.inject(MessageBodyParameterInjector.java:146) [:6.0.0.Final] at org.jboss.resteasy.core.MethodInjectorImpl.injectArguments(MethodInjectorImpl.java:114) [:6.0.0.Final] at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:137) [:6.0.0.Final] at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:252) [:6.0.0.Final] […]

通过Spring MVC将二进制文件上传到MySQL的正确方法

我正在尝试将文件上传到MySQL,但是我无法正确地执行此操作。 我正在使用云平台将Java Spring应用程序作为网站运行。 控制器: byte[] bytes = file.getBytes(); // file is MultipartFile DFile newFile = new DFile(); // my object newFile.setName(name); // name column newFile.setType(type); // Blob blob = new SerialBlob(bytes); // set the blob from binary newFile.setData(blob); fileService.insertFile(newFile); // calls to insert into MySQL 道:两种不同的方式 length = (int)blob.length(); byte[] b = blob.getBytes(1, length); InputStream […]

将Flash文件上载与JSF集成

我已经看到我们可以通过flash文件上传来上传多个文件。 像SWFUpload或YUI Uploader 。 是否可以将这些上传组件与JSF集成? 我想要的是一次选择多个文件。 Primefaces文件上传器具有此function,但在IE7中不起作用,因为IE7没有任何HTML5支持。 我需要创建一个包含各种字段的表单,如下拉菜单,文本输入等,还需要添加文件上传器以选择多个文件。 当点击JSF提交按钮时,表格将被validation,之后将继续。 我已经创建了一个用于上传多个文件的页面,但该页面使用多个输入文件组件来存储多个文件。 任何参考对我都非常有帮助。 我找到了另一个SO线程 ,其中发布的解决方案使用JSP。 我无法理解如何使用它来满足我的要求。 更新 我创建了以下托管bean: import com.mhis.massupload.ucm.Service; import java.util.List; import java.util.UUID; import java.util.logging.Logger; import javax.faces.context.FacesContext; import org.apache.commons.fileupload.FileItem; public class UploadBean { private Logger log = Logger.getLogger(getClass().getName()); private Service service; private String key; public UploadBean() { super(); log.info(“JYM”); init(); } private void init() { key […]

为什么这个exceptionFileItemStream $ ItemSkippedException?

在gwt Web应用程序中。 我必须发送一个文件和一些附加的参数。 在ServerSide上 try { ServletFileUpload upload = new ServletFileUpload(); FileItemIterator iterator = upload.getItemIterator(request); while (iterator.hasNext()) { FileItemStream item = iterator.next(); if (item.isFormField()) { String fieldName=item.getFieldName(); String fieldValue = Streams.asString(item.openStream()); System.out.println(” chk ” +fieldName +” = “+ fieldValue); } else { stream = item.openStream(); fileName = item.getName(); mimetype = item.getContentType(); int c; while ((c […]

IE 11:发送Multipart Form Data请求时出错:Stream意外结束

我正在尝试使用jQuery AJAX调用上传文件和其他一些表单字段。 这是一个调用服务器上URL的常用函数: function uploadDocument(rquestURL,formId,callback){ $.ajax({ type : ‘POST’, url : rquestURL, cache:false, processData:false, contentType:false, data : new FormData($(“#”+formId)[0]) }).done(function(response) { callback(response); }); } 在从浏览器的开发工具中检查时,这些是相应的请求内容: 来自IE11 —————————–7dfad39402e6 Content-Disposition: form-data; name=”subject” Test —————————–7dfad39402e6 Content-Disposition: form-data; name=”message” Test test —————————–7dfad39402e6 Content-Disposition: form-data; name=”announcementAttachment”; filename=”” Content-Type: application/octet-stream —————————7dfad39402e6 铬 ——WebKitFormBoundaryp8rj3ArKDsbYw0BZ Content-Disposition: form-data; name=”subject” Test ——WebKitFormBoundaryp8rj3ArKDsbYw0BZ Content-Disposition: form-data; name=”message” […]

使用Java将包含文件的目录上载到S3

我正在处理用户将ZIP文件上传到我的服务器的应用程序,在ZIP文件将被扩展的服务器上,然后我需要将其上传到服务器。 现在我的问题是:如何使用Java到S3存储桶上传包含多个文件和子文件夹的目录? 那有什么例子吗? 目前我正在使用JetS3t管理我与S3的所有通信。

HTTP PUT以Java格式上传文件

编辑:我想我已经弄清楚如何做二进制数据部分。 在代码中仔细检查它,但我很确定我做对了。 现在,我在尝试按照Vimeo API文档中的描述完成上传时遇到了新错误 编辑2:将 .debug()添加到OAuthService并更新输出。 原始问题 :我正在尝试使用Vimeo API(流媒体方法)将video上传到Vimeo。 我正在使用scribe来授权我的应用,获取我的访问令牌并准备上传video。 在这个PUT的HTTP请求示例中,我只是不知道该怎么做Vimeo API文档说“你的文件的二进制数据”。 PUT http://1.2.3.4:8080/upload?ticket_id=abcdef124567890 HTTP / 1.1 主持人:1.2.3.4:8080 内容长度:339108 内容类型:video / mp4 ….你的文件的二进制数据在这…. 我可以得到罚单和标题。 它只是,我该怎么做才能插入我的文件的二进制数据? 笔记: 它是Java中的桌面应用程序 这是我正在测试的一个小video文件 这是我的put代码(记住,我正在使用scribe ) // Setup File (line 52) File testUp = new File(“C:/Users/Kent/Desktop/test.mp4”); String contentLength = Long.toString(testUp.length()); System.out.println(“The content length is: ” + contentLength); byte[] fileBytes = ByteStreams.toByteArray(new […]

如何移动Primefaces-Upload-Temp-Files而不是进行时间密集的复制过程?

我想用Java EE上传大于2 GB的文件并使用primefaces。 总的来说,这不是什么大问题,但我有一点问题。 PrimeFaces的常用方法是上传文件,使用UploadedFile-Object,从中获取InputStream,然后将其写入磁盘。 但是写入磁盘大文件是一项耗时的任务。 相反,我想在文件系统中找到上传的文件,然后将其移动到我存储所有文件的文件夹,因为移动文件不会浪费时间。 所以,根据这个问题,我想出了设置PrimeFaces-Tmp文件夹和大小限制,当文件放在那里。 现在每个上传的文件都直接进入该文件夹。 关键是,我现在在磁盘上有一个文件,而用户正在上传 – 之后不再创建它。 到现在为止还挺好。 我可以识别文件并移动它(虽然它有一个奇怪的名字)。 但是指向Primefaces Userguide(页187) ,此Tmp-Folder仅在内部使用。 我甚至会从Primefaces窃取UploadedFile-Object的内容。 对我来说似乎不是一个干净的解决方案。 任何提示如何实现这一目标? 我也看到了这个问题 。 也可能是我的头衔,但这不是我想要的。 编辑: 由于评论,一些代码。 首先,我在fileUploadListener中收集UploadFile-Objects: public void handleFileUpload(FileUploadEvent event) throws IOException { FacesMessage msg = new FacesMessage(“Succesful”, event.getFile().getFileName() + ” is uploaded.”); FacesContext.getCurrentInstance().addMessage(null, msg); getUploadedFilesDTO().add(new UploadedFileDTO(event.getFile(), uploadedFilesCounter)); uploadedFilesCounter++; } 在EJB的第二个我为每个UploadedFile-Object调用copyFile: private void copyFile(UploadedFile uploadedFile, […]