我正在尝试使用我的TML中的Tapestry上传表单上传文件
在.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 :(得分:0)
调试org.apache.tapestry5.upload.components.Upload processSubmission方法。检查请求中的内容。