Spring Boot文件在下载时损坏

时间:2019-01-31 19:47:12

标签: java spring-boot base64

我存储了不同类型的文件,并且我有一个控制器来下载文件。该文件存储在base64中,我正在尝试下载该文件,尽管下载工作正常,但该文件似乎已损坏。我真的可以使用一些指针来解决我的问题。

这是我到目前为止所拥有的。

@GetMapping("/attachments")
public ResponseEntity<InputStreamResource> getAttachment() {
    String file = "iVBORw0KGgoAAAANSUhEUgAAALoAAAAyCAYAAADr7cFEAAAgAElEQVR4nO2df3idVZXvP99MzGTOye1Ne1NuH26pEJgKiLXlxJogKhRFYBwFfyDiNMjAiUKioMg4yFAeisAwWLxqU0qODJAq6r0KyI+K6FRBxxbmHIhMp3QQIpdCp1Ny29w+nPN0Mpl87x/vz3NykqYV7p3Rrj7pec/77nfttddee+211l57HzgIB+F3APRaIj+is3epxBXAO4BGoIh90/CmNQ+9lvUehINQC6+ZoLd39p4NvhPUXFWTmUB8HvjS8Mb+qncGh17+c1vrz1vS9tRrRddB+N2EhtcCaXtX7zzjWwzNJvzn8A832L4BWDT5Te2S2Ds4NNL4WtB1EH534TURdOwzJc0RIAkJhMJrIanR+Pza17oXtw0AHcDfDw6NtAAMPvny0sGhkdLgky/Pry0/ODTy2tB/EH7r4IA0Z3tnbwPiUPChoJ3gF4c3rhmPnhveIKg2jGqMJKGjpkC/1fZ9kvaG3/dgtiL2pgsNPjlyInD74NDI7cD13YvbDqQpVZAtlOYAzQaEAY0DO8v53P7gaAQOAQIMyeeucj63N1sotRjPCoZ+8Iygvu3lfMf+1JMxtCYWYZrF8bdxoGLzSqVn320IaGMWEd0GBUi37w8P/j3CfmvEIzovPsr4QeA54DGbXxn9rL2rtzMqI+llCNhtAoY59R3A9q56+I23Is0zfnBwaOTQ7iVztyKfj3X24NDIGYNDI2ElLDU+Cjh9f9tQDzKFYhP23wEvyX4J8xL4acP+jqBjgZdiPPASwecZALY/LRTXIfsl4ZdA+6d0zLmyX3JYR3xtvwSKrreBf41cygyUvpItFE8IB2J9lOZSwUtyRHPwZ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sgOlplf3h1LtB5Fqdx0h9G3wMaA/V/zDscZoAvtu4OpXlY6DUAXZQum0cBtcsZzPvZItFIuSKrZD21ffkvhEtlCKfLE5BLt7fhxo/ABq8g1fQGrPFkoLCX4qcwHwsahkCLsUnLTcni2UNgNN5XxuzCmNXs7nyBaK3yI4e/528FZQq83lMg871Oz1TktIUq4DyBRKnxXcgb0L6UWkvxfBceOvqqB3L5lbe3YhAMOb+ifaO3uvQjxIwIx2rJ0S9yA9cND2fs1hHuIezPOZgeJ2ggjZM5IGAQRfsv0Wib+zeRaYj9iuWHDBeCId95a5z/LlmBKwA9SK2GSCY+HCl4oWmwWP2H6e8CxFoYmqxGXz34XfgihhthofLmk78LFKnKBlcHXcXWLC9kSyydrnA1cbnsJuRBwt85lyT8fYlJbPQfjtgmyheChWR7hL61mgmM7yC53C4wULsXdY+nkllcqcLZQONW6s5DvizQzZgVLG8jKhJuBRzDhinvEz0WnImYFShqBMMzBUzueezRSKbUKt5Xzu2XT9wPFAtKf45+lU6kyheKigsZyuv1BqA7dCkNAVbrQ5HtFOkP69KTr65P8CEtHnF7Z82nMAAAAASUVORK5CYIIA";
    String decoded = new String(Base64.decodeBase64(file.getBytes()));

    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Encoding", "UTF-8");
    headers.add(HttpHeaders.CONTENT_DISPOSITION,"attachment; filename=" + fileName);
    InputStream targetStream = IOUtils.toInputStream(decoded, "UTF-8");

    return ResponseEntity.ok().headers(headers).contentLength(decoded.length())
                                                .contentType(MediaType.parseMediaType("application/octet-stream")).body(new InputStreamResource(targetStream));

}

1 个答案:

答案 0 :(得分:0)

基本64位编码文件是PNG文件。 PNG文件是二进制文件,并且不能被表示为字符串,并且不UTF-8编码。只返回字节数组。

@GetMapping("/attachments")
public ResponseEntity<byte[]> getAttachment() {
    String file = "iVBORw0KG ... 5CYIIA";
    byte[] decoded = Base64.getDecoder().decode(file);

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);

    ContentDisposition contentDisposition = ContentDisposition.builder("attachment")
        .filename(fileName).build();
    headers.setContentDisposition(contentDisposition);

    return ResponseEntity.ok().headers(headers)
        .contentLength(decoded.length)
        .body(decoded);
}