2017-12-03 168 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方法。檢查來自請求的內容。