2

I have problem with Zippex encoding. When I create archive with file name 'Check Flät', the name changes to strange symbols.

Code that create attachment:

Zippex sampleZip = new Zippex();
Blob fileData = Blob.valueOf('Sample text.');
sampleZip.addFile('layouts/Check Flät.layout', fileData, null);

Attachment attachment = new Attachment();
attachment.Name = 'Check Flät';
attachment.ContentType = 'application/zip;charset=UTF-8;';
attachment.Body = sampleZip.getZipArchive();
attachment.Description = 'Layout';
attachment.ParentId = 'a072h000002jr3oAAA';
insert attachment;

What I am getting in archive:

enter image description here

Check Fl├дt.layout

But I want to get Check Flät.layout in name of the File.

4
  • Have you looked at the source code of Zippex on github to identify the issue?
    – identigral
    Commented Apr 13, 2022 at 14:51
  • yes, I tried, but I do not know where it can be. Any encoding I tried, for example urlDecode/urlEncode is not working. Also I tried to debug this. In Zippex class all variable which can contain Name are showing right value. I think this issue in archive creating or smth. Commented Apr 13, 2022 at 15:57
  • Are you urlEncoding to ASCII or UTF8? You're probably doing the latter but you might want to do the former. This is more of an interoperability issue rather than correct encoding e.g. github.com/girder/girder/issues/985 Some other conversion techniques are described here: salesforce.stackexchange.com/questions/7368/…
    – identigral
    Commented Apr 13, 2022 at 17:13
  • 1
    @identigral I was encoding to UTF8. But I tried to do the same now with ASCII, and no result. Maybe I am doing something wrong. Commented Apr 14, 2022 at 9:19

1 Answer 1

4

Checking out the specifications, the file name needs to be in ASCII format. This is what's causing the problem you're seeing. To set the UTF-8 file name, you need to specify an Extra Field.

4.6.9 -Info-ZIP Unicode Path Extra Field (0x7075):

       Stores the UTF-8 version of the file name field as stored in the
       local header and central directory header. (Last Revision 20070912)

         Value         Size        Description
         -----         ----        -----------
 (UPath) 0x7075        Short       tag for this extra block type ("up")
         TSize         Short       total data size for this block
         Version       1 byte      version of this extra field, currently 1
         NameCRC32     4 bytes     File Name Field CRC32 Checksum
         UnicodeName   Variable    UTF-8 version of the entry File Name

Looking at the source, I see:

    tempFileObject.extraFieldLength   = '0000';// (2 bytes) , creates (e)
    tempFileObject.extraField         = '';

Which means it's not actually attempting to set an extraField with the extended file name header. You'll need to patch Zippex to support UTF-8 file names. Aside from that, you should use only ASCII characters in the primary file name. I recommend you read the specs for additional information.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .