首页 > 解决方案 > spring boot rest 下载 docx

问题描述

我正在尝试下载 docx 文件但编码出错

@GetMapping(value = ["/get-file"], produces = [MediaType.APPLICATION_OCTET_STREAM_VALUE])
@ResponseBody
@Throws(IOException::class)
fun getFile(): ByteArray {
    val file = File("somePath\\data.docx")
    val fis = FileInputStream(file)
    return IOUtils.toByteArray(fis)
}

我能用这个做什么?

PKEi#P[Content_Types].xmlŖ�N�0E%�5。!����$��ֵ'���=���L�6B�i�b9��s��I���5�+��+��q>d8�v��=Mn �,�(��;(����r<�|T3��b����Q������)�V ����|3�'����!8 ]��G�P����}^�.��*��@��N�,�L�s]�#2��杪��!52�G�������Ӿ��Gh�,����Ҕ\."z�l�C c@ K��NX*�;��6����P�L�T�dn�9��S��h��Wm<�j� |P�+!Fjbk�N�B�o��w��t�ㆭhVjR��jM���f�NNA�}�v���E��?�&��҈��bB �mB��m����i�`w~�&p;�@����""�zq��E���&��!�~z����^�v “L������7?|�OPK�<�。

标签: springrestfilekotlindocx

解决方案


docx的媒体类型是:

application/vnd.openxmlformats-officedocument.wordprocessingml.document

推荐阅读