Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache commons fileupload Apache Commons文件上载仅保存文件的一部分_Apache Commons Fileupload_Gwtupload - Fatal编程技术网

Apache commons fileupload Apache Commons文件上载仅保存文件的一部分

Apache commons fileupload Apache Commons文件上载仅保存文件的一部分,apache-commons-fileupload,gwtupload,Apache Commons Fileupload,Gwtupload,我正在使用gwt小部件gwtupload.client.Uploader,并尝试使用fileupload流式api将文件保存到数据库中的blob列中。 问题是,如果文件大于3k,则只保存3k(井3.25K)。 谢谢你的帮助。 代码如下: try { ServletFileUpload upload = new ServletFileUpload(); upload.setProgressListener(listener); FileItemIterator iter =

我正在使用gwt小部件gwtupload.client.Uploader,并尝试使用fileupload流式api将文件保存到数据库中的blob列中。 问题是,如果文件大于3k,则只保存3k(井3.25K)。 谢谢你的帮助。 代码如下:

try {
    ServletFileUpload upload = new ServletFileUpload();
    upload.setProgressListener(listener);
    FileItemIterator iter = upload.getItemIterator(request);
    InputStream stream = null;
    while (iter.hasNext()) {
        FileItemStream item = iter.next();
        String name = item.getFieldName();
        stream = item.openStream();
        Object o = getThreadLocalRequest().getSession().getAttribute(PortailServiceIMPL.FICHIER_SESSION_STORE_KEY);
        if (o != null && o instanceof Fichier) {
            uploadService.sauvegarder((Fichier) o, stream);
            listener.update(listener.getContentLength(),
                    listener.getContentLength(), 0);
        } else {
            throw new RuntimeException(
                    "Impossible de recuperer le fichier de la session.");
        }
    }
    if (stream != null) {
        stream.close();
    }
} catch (SizeLimitExceededException e) {
    RuntimeException ex = new UploadSizeLimitException(
            e.getPermittedSize(), e.getActualSize());
    listener.setException(ex);
    throw ex;
} catch (UploadSizeLimitException e) {
    listener.setException(e);
    throw e;
} catch (UploadCanceledException e) {
    listener.setException(e);
    throw e;
} catch (UploadTimeoutException e) {
    listener.setException(e);
    throw e;
} catch (Exception e) {
    logger.error("UPLOAD-SERVLET (" + request.getSession().getId()
            + ") Unexpected Exception -> " + e.getMessage() + "\n"
            + stackTraceToString(e));
    e.printStackTrace();
    RuntimeException ex = new UploadException(e);
    listener.setException(ex);
    throw ex;
}
保存文件的lina是:

uploadService.sauvegarder((Fichier) o, stream);
在到达代码后,有4种方法保存InputStream(不接触InputStream):

如果我使用FileItemFactory,它可以工作,但这不是我想要的:

FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List<FileItem> uploadedItems = upload.parseRequest(request);
    for (FileItem item : uploadedItems) {
        InputStream stream = item.getInputStream();
FileItemFactory工厂=新的DiskFileItemFactory();
ServletFileUpload upload=新的ServletFileUpload(工厂);
List uploadedItems=upload.parseRequest(请求);
对于(文件项:uploadedItems){
InputStream=item.getInputStream();

谢谢你的帮助。

经过一番努力,我解决了这个问题

在storeBlob方法中,我无法使用pInputStream.available()。因此,我使用了以下行:

ps.setBinaryStream(1, pInputStream);
ps.setBinaryStream(1, pInputStream);