背景:
在FPM应用开发中,会有需求需要同时下载多个文件。当文件过多时,逐个进行下载即拖慢效率,又影响体验。
应用:
使用zip类cl_abap_zip将多个文件处理为常见的zip压缩包进行下载。
步骤:
声明对象
DATA lo_zip TYPE REF TO cl_abap_zip.
实例化
CREATE OBJECT lo_zip.
将单个文件的xstring编码添加到压缩包中
lo_zip->add(
EXPORTING
name = filename
content = xml_xstring ).
获取生成的压缩包的xstring编码
lv_zip_xstring = lo_zip->save( ).
下载zip文件
cl_wd_runtime_services=>attach_file_to_response(
EXPORTING
i_filename = filename
i_mime_type = 'ZIP/APPLICATION'
i_content = lv_zip_xstring ).
附加:
zip压缩包中含中文名文件时需要设置如下参数,否则文件名乱码
lo_zip->support_unicode_names = abap_true.
获取文件的crc32值可以用来文件校验
crc32 = cl_abap_zip=>crc32( content = xstring ).