1

I've read that it is possible to get primefaces fileUpload to work with google appengine with a bit of tweaking. It requires apache fileupload and common io, so I added commons-fileupload-1.2.2.jar and commons-io-1.3.2.jar to my WEB-INF/lib folder.

Then following the instructions of primefaces, I added their servlet:

<filter>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
    <init-param>
        <param-name>thresholdSize</param-name>
        <param-value>2147483647</param-value>
    </init-param>       
</filter>
<filter-mapping>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>  

The thresholdSize is put purposefully high because it is the number of bytes by which the file will be saved to disk rather than retain it in memory, and since no files can be saved using google appengine, it can never be an option.

The actual usage is as follows:

<h:form enctype="multipart/form-data">
    <!-- Other text fields go here -->
    <p:fileUpload fileUploadListener="#{tjBean.onHandleFileUpload}"  
        mode="advanced"  
        update=":toolbarForm:globalMessages"  
        sizeLimit="500000"   
        allowTypes="/(\.|\/)(txml)$/" /> 
<p:commandButton value="Okay" ajax="false" actionListener="#{tjBean.onSaveAction}" />
</h:form>

I've understood that the commandButton must not use ajax and that it must be a full page reload. It seems to let me upload the file without a hitch, but the actionListener never gets triggered. Submitting then the form with the commandButton triggers an exception:

java.lang.NoClassDefFoundError: Could not initialize class org.apache.commons.fileupload.disk.DiskFileItem
    at org.apache.commons.fileupload.disk.DiskFileItemFactory.createItem(DiskFileItemFactory.java:199)
    at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:361)
...

I'm not sure what I'm doing something wrong or I simply did not get the appropriate versions of the apache libraries to make this work properly. The version of primefaces that I'm using is 3.2. When I search for a solution to this problem, the common response is that google appengine doesn't like the fact that I'm trying to save a file to the disk, and the solution is simply to increase the threshold, but the threshold is as high as it can be, so it shouldn't even be attempting to save the file to disk.

I'd appreciate any help or suggestions, especially if the solution is glaringly obvious and I have yet to see it. Thanks in advance.

4

3 回答 3

1

通过覆盖 Apache 文件上传库 1.2.2 的 DiskItem 修复了该问题。

具体来说,注释了静态字符串 UID(它使用列入黑名单的类 java.rmi.server.UID)和 write 方法的全部内容(我将阈值设置得很高,因此它永远不需要调用它)。

显然这不是理想的解决方案,但只要我不需要更新文件上传库,它就可以工作,我怀疑我在不久的将来需要这样做。

于 2012-04-08T21:01:38.447 回答
1

尼尔,你不能写入磁盘(即你不能在 GAE 上使用 fileupload.disk)。

App Engine 文件系统对于您的应用程序始终是只读的。您可能会考虑的几个替代方案是:

另外,看看这个: http: //primefaces-rocks.appspot.com/ui/fileUploadSimple.jsf

于 2012-04-08T19:19:06.500 回答
1

@尼尔

我很抱歉,但我无法发表评论。你能告诉我你是如何改变方法的吗

getTempFile() {
        if (tempFile == null) {
            File tempDir = repository;
            if (tempDir == null) {
                tempDir = new File(System.getProperty("java.io.tmpdir"));
            }

            String tempFileName = format("upload_%s_%s.tmp", UID, getUniqueId());

            tempFile = new File(tempDir, tempFileName);
        }
        return tempFile;
    }

你用什么代替了UID?

于 2014-01-29T09:45:55.697 回答