0
文件我有這樣錯誤下載使用JSF和Primefaces
@Entity
public class myFiles implements Serializable{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int idmyFiles;
@Lob
private File myFile;
getters and setters...
我,似乎工作的上傳表單的實體,當我上傳一個文件,我可以看到它在postgtes表。
的形式(我用primefaces)我有這個
<p:fieldset id="myFiles" class="recuadro" legend = "Upload a fileos">
<p:fileUpload value="#{abmBean.fichero}" mode="simple" />
<p:commandButton id="btnSubir" ajax="false" process="@all" update="@all"
action="#{abmBean.uploadFile()}" value="Subir" />
</p:fieldset>
這是上傳文件
public void uploadFile() {
File destFile = new File("/tmp/"+fichero.getFileName());
FileUtils.copyInputStreamToFile(fichero.getInputstream(), destFile);
/* Then I just create a myFile object F and just F.setFile(destFile) */
}
看來工作
要下載文件的方法我有這個方法
public downloadFile(int id) {
/* the int id is the id of the myfile object F */
/* I retrieve from the database the F object and then this*/
File fichero = new File("/tmp/"+F.getFile.getName());
FileUtils.copyFile(F.getFile, fichero);
Faces.sendFile(fichero, true);
}
這一切正常,我有迴文件
但問題是這樣的,我知道我上傳的文件也被複制到/ tomcat7/bin文件夾以及如果我從那裏刪除文件,然後,當我想下載它我得到一個fileNotFoundException。
所有我需要的是能夠給用戶的文件從
我使用Tomcat7提供數據庫,Java 1.6的(是很老)Primefaces 6時,PostgreSQL 9.1和JSF2的Debian
你的標題有誤導之嫌,我沒有看到任何OmniFaces組件而是PrimeFaces(如在標籤註明)。另外,請檢查管理文件上傳的後臺bean是否具有['@ MultipartConfig'註釋](http://docs.oracle.com/javaee/6/tutorial/doc/gmhal.html)。另一方面,請檢查PrimeFaces配置中的默認上傳文件夾([文檔鏈接,第223頁](https://www.primefaces.org/docs/guide/primefaces_user_guide_6_1.pdf))。我假設'myFiles'實體中的getter從正確的文件夾中獲取 – Al1
謝謝我更改了標題,我的backingbean沒有@MultipartConfig,我將會檢查您建議的手冊頁 – Alexev
該文件在數據庫中作爲二進制文件而不是作爲字符串路徑 – Alexev