2017-12-03 94 views
0

我试图使用Tapestry的上传表单在我的TML挂毯文件上传和随之而来的转换为byte []

在.tml文件上传到获取文件:(这直接来自https://tapestry.apache.org/uploading-files.html

<t:form> <t:errors/> <input t:type="upload" t:id="file" t:value="file" validate="required"/> <br/> 
<input type="submit" value="Upload"/> </t:form> 

在页面名为.java:

@Persist @Property private UploadedFile file; 

public void onSuccess() { 
     byte[] fileContent = null; 
     fileContent = IOUtils.toByteArray(file.getStream()); 

} 

我得到一个空指针异常,当我尝试UploadedFile的转换为字节数组。我想将它转换为一个字节数组,以便我可以将其存储在数据库中。我已经尝试了许多不同的方法转换为字节数组或使用文件路径来访问文件,但没有任何工作。可能相关的信息是file.getPath()只是返回文件的名称。

我在想,由file.getstream()生成的InputStream格式不正确。

回答

0

调试org.apache.tapestry5.upload.components.Upload processSubmission方法。检查来自请求的内容。