796
Views
10
Comments
Solved
Adding Additional Files in ZIP file
Question

Hi! Is it possible to add additional files when a zip file is already present.


Example:

I have a zip file with 10 .pdf files. I wanted to add more .pdf files inside. I tried downloading the zip file, use LoadZip then AddFiles, but it overwrites the existing files inside the zip.

2019-06-15 21-39-22
Afonso Carvalho
 
MVP
Solution

Hi Tiago,

I believe you're only supposed to commit once: when you're done adding all of your files. If you have multiple commits in your code, you'll overwrite the zip content each time.

2019-05-22 11-30-09
Marcelo Ferreira

Hi Clifford,

Looks like a bug. For know what you can do is get the files from zip and add them again

Regards,

Marcelo

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Clifford,

This is indeed the current behaviour, but it's not a bug as Marcelo suggests, it's by design - or rather, the current Zip Extension does not provide for adding files to an exisiting ZIP file. It's unfortunate the documentation (if there is any) doesn't explicitly state that.

As a workaround, you can indeed follow Marcelo's example, i.e. adding all the files after retrieving them, then add the new files. This is not very efficient, but currently the only way.

2019-05-22 11-30-09
Marcelo Ferreira

Hi Kilian,

Do you know why it was done like this by design? There is any technical challenge?

Regards,

Marcelo

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Marcelo,

Probably because it's the most straightforward design, given they use SharpZipLib. You need to do some extra stuff to modify an existing file, and you need to detect whether the current file is emtpy or not. Also, it might just be that wasn't possible with SharpLibZip when they started using it, and they haven't changed the interface since ages.

UserImage.jpg
Clifford Marco

Hi Marcelo,


Yes indeed that is a good work around. I have tried it. However, for a much larger data do you think it is still possible? I have like 6000+ .PDF files to consolidate in a single zip file. I also tried using process (background process) but the server times-out at around 200th when I try to re-add the files. Any suggestions to increase the life of a process for it to finish the re-adding of files?


Thanks!

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Clifford,

If you're working with such big ZIP files, perhaps the BigZip Forge component might be of interest (disclaimer: I've never used it myself).

2019-05-22 11-30-09
Marcelo Ferreira

Hi Clifford,

I also did some tests with the component that Kilian mention and the addfile work when you load a zip. Since you need to add so many files to the zip what you can do is use a timer and add 100 files after that check if you still have more files to add and if yes launch the timer again. you can watch this https://www.outsystems.com/learn/courses/43/master-class-on-best-practices-and-timers/?StartCourse=False to understand what i mean.(if you only want to check the timers part go to 2h14m)

Regards,

Marcelo

2017-02-01 17-35-56
Tiago Carvalho

Hello everybody!

I need to create a zip file with 4 simple text files inside but i'm stuck with this problem.

I tried different ways to solve it (i tried the Marcelo's solution but give me an error or the result is the same overwriting...) but the final file overwrite all others.

First i have the action createzip, then an action to get the binary content, then the action addfile -> commit changes -> getfiles with a foreach cycle and inside that foreach i use the action add file and commit changes again.

Same thing for the other 3 files.

Can someone explain me the correct order /actions to generate a zip file with multiple files inside?


Thanks in advance 

2019-06-15 21-39-22
Afonso Carvalho
 
MVP
Solution

Hi Tiago,

I believe you're only supposed to commit once: when you're done adding all of your files. If you have multiple commits in your code, you'll overwrite the zip content each time.

2017-02-01 17-35-56
Tiago Carvalho

Thats it Afonso!


Problem solved.


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.