Skip to main content

As part of an API that i'm using I need to encode a .zip file to base64, but I haven't succeeded to do this using the attribute-, text- or binaryencoder transformers of fme. As an attachment I added the file 'receptors1.zip' that I'm trying to encode to base64 in fme. From a debugging script of the API I know for a fact that the base64 encoding that i'm looking for equals:

UEsDBBQAAAAIADVVSkv67CW/DQEAABwDAAAOAAAAcmVjZXB0b3JzMS5yY3CN0l1KxDAQB/B3wTvkBDKfycxpyqLiy+4WFlbU0ztJS5KqD7b8Gyj9MZNJr7d0PV1e08fyvK639Lktp/e35QvSy3pZzvd0vmOEIhyRiEZypEQs4o8PkIRE2TlhNiueRNQVEjwBmasnTG4J9pu2dTAJ5pDzzATZglnpDKk+ustOVMt5oXAZQJrLzlSddpcjPjOu5VB9ZsUx1y65M4lwZyaK2+Y2pnZgdGAyMxqbG0y0BMtjc7Vdstm1Lin4cAxx1XLNjMHA7Nowhe23iw+PcDh3g2mYiLgNUwrWPqWDUvv02eE+ze5GvXg5FxOcXZsLi/7hHA/uUK6NRRl39q/tKSr4dHqYdT+Gn/+K9nF+A1BLAQI/ABQAAAAIADVVSkv67CW/DQEAABwDAAAOACQAAAAAAAAAIAAAAAAAAAByZWNlcHRvcnMxLnJjcAoAIAAAAAAAAQAYAABnoJijQdMBAPB4SNxC0wFgWzSbL0PTAVBLBQYAAAAAAQABAGAAAAA5AQAAAAA=

On the website https://www.base64encode.org/ I have verified that this 'physical .zip file' indeed results in the above base64 encoding.

At first I used the text file reader in FME (while having set the reader parameter 'Read whole file at once' to 'yes') to read the .zip, combined with either the text- or binaryencoder transformers from fme to encode the file to base64. Both these transformers result in the encoding:

bnIgbmFtZSB4X2Nvb3IgeV9jb29yIGF2Z196MCBkb21fbHUgbHUxIGx1MiBsdTMgbHU0IGx1NSBsdTYgbHU3IGx1OCBsdTkNCjAgNDI0NTM5MyAxNjg4NzkgNDQ1OTUwIDAuMDI4OTU5IDEgOTggMCAwIDAgMCAyIDAgMCAwDQowIDQyNDUzOTQgMTY5MDY2IDQ0NTk1MCAwLjAyNDEzOCAxIDg3IDAgMCAwIDAgMTIgMCAxIDANCjAgNDI0NjkyMiAxNjg5NzIgNDQ2MDA0IDAuMDI2OTMyIDEgODUgMCAwIDAgMCA2IDAgOSAwDQowIDQyNDY5MjMgMTY5MTU5IDQ0NjAwNCAwLjAyNzkxNiAxIDkzIDAgMCAwIDAgNCAwIDMgMA0KMCA0MjQ4NDUxIDE2ODg3OSA0NDYwNTggMC4wMjc5MTYgMSA5MiAwIDAgMCAwIDQgMCA0IDANCjAgNDI0ODQ1MiAxNjkwNjYgNDQ2MDU4IDAuMDI3NDU3IDEgNjcgMCAwIDAgMCA1IDAgMjggMA0KMCA0MjQ4NDUzIDE2OTI1MiA0NDYwNTggMC4wMzAwMDAgMSA5MCAwIDAgMCAwIDAgMCAxMCAwDQowIDQyNDg0NTQgMTY5NDM4IDQ0NjA1OCAwLjAzMDAwMCAxIDEwMCAwIDAgMCAwIDAgMCAwIDANCjAgNDI0OTk4MCAxNjg5NzIgNDQ2MTExIDAuMDI2NDcxIDEgNjQgMCAwIDAgMCA3IDAgMjkgMA0KMCA0MjQ5OTgxIDE2OTE1OSA0NDYxMTEgMC4wMzAwMDAgMSA1OSAwIDAgMCAwIDAgMCA0MSAwDQowIDQyNDk5ODIgMTY5MzQ1IDQ0NjExMSAwLjAzMDAwMCAxIDkxIDAgMCAwIDAgMCAwIDkgMA0KMCA0MjQ5OTgzIDE2OTUzMSA0NDYxMTEgMC4wMzAwMDAgMSAxMDAgMCAwIDAgMCAwIDAgMCAwDQowIDQyNTE1MDkgMTY4ODc5IDQ0NjE2NSAwLjAyNzQzMiAxIDg1IDAgMCAwIDAgNSAwIDEwIDANCg==

On the website https://www.base64encode.org/ I have been able to verify that this is the base64 encoding of the receptors1.rcp file that is contained in the .zip file, and not the encoding of the 'physical .zip file'. I have also tried to use the 'datafile reader' to read the .zip file, but again it seems to open the contents of the .zip file and encode the receptors1.rcp file that is contained in the zip, but not the actual .zip file.

While further looking for a solution I found the custum transformer 'FileRawDataFetcher', but I'm quite unfamiliar how I can use this transformer. I found quite detailed documentation about this transformer on the FME hub, i.e. https://hub.safe.com/transformers/filerawdatafetcher. Specifically I don't really know what kind of 'Interpretation Specifiers' (i.e. one of the user parameters of this custum transformer) I would need to use to solve the problem I'm experiencing. From the referred documentation link, by means of experiment I tried '0, int8', resulting in the output '80', which doesn't lead me somewhere...

 

Besides this, a friendly colleague from the live chat linked me to the following question on the forum: https://knowledge.safe.com/questions/69728/binary-string-to-zip-file-in-memory.html. In the topic it seems like the opposite of my question is tackled, which was approached by takashi using a bit of Python code. I wouldn't doubt that Python code could also solve my problem, but unfortunately I'm not too much of a Python programmer :(

 

If anyone has any ideas or suggestions of tackling this problem with FME, that would really be appreciated!

 

Kind regards,

Thijs

 

 

This way might help you: Read the zip file with the AttributeFileReader (Source File Character Encoding: Binary (fme-binary)) and encode the read file contents with the BinaryEncoder (Encoding Type: Base64).


This way might help you: Read the zip file with the AttributeFileReader (Source File Character Encoding: Binary (fme-binary)) and encode the read file contents with the BinaryEncoder (Encoding Type: Base64).

That did the trick. Thank you so much!


Reply