1

これはフォーラムでの私の最初の質問です。これで私を助けてくれることを願っています。 私の余談:

  1. ブラウザからダウンロードしたい基本のファイル
  2. 私はprimefaces、FileDownload、およびStreamedContentを使用しています

問題

問題は、ファイル 0 バイトをダウンロードすることです。

私のview.xhtml:

<p:commandButton id="downloadLink" value="Descargar" ajax="false" onclick="PrimeFaces.monitorDownload(start, stop)"   
                                         rendered="#{not anexoController.ingresaDatos}" icon="ui-icon-arrowthichk-s">  
                            <p:fileDownload value="#{anexoController.file}" />  
                        </p:commandButton>

私のダウンロードマネージャー

    public StreamedContent getFile() {
    file = null;
    byte[] bytes = anexoActual.getArchivo(); //anexoActual.getArchivo.length = 53508
    String nombre = anexoActual.getNombre(); 
    String formato = anexoActual.getFormato();
    InputStream stream = new ByteArrayInputStream(bytes);
    try {
        stream.read(bytes);
    } catch (IOException ex) {
        Logger.getLogger(AnexoController.class.getName()).log(Level.SEVERE, null, ex);
    }
    file = new DefaultStreamedContent(stream, formato, nombre);
    return file; //file.steam.buf.length = 53508
}

ご覧のとおり、ファイルは 53508 バイトの長さのファイルに到達しますが、ダウンロードが完了すると、ファイル名とデータ型しかわかりません

4

1 に答える 1

4

このコードを見てください:

try {
    stream.read(bytes);
} catch (IOException ex) {
    Logger.getLogger(...)
}

ストリームから読み取っています-開始するデータを含むバイト配列に戻ります。どうしてそんなことをするのか?ストリームを最後に配置しています。

そのブロックを取り除くだけで、うまくいくかもしれません。

于 2012-07-31T19:17:02.803 に答える