How to send zip files in the python Flask framework?

BytesIO() needs to be passed bytes data, but a ZipFile() object is not bytes-data; you actually created a file on your harddisk. You can create a ZipFile() in memory by using BytesIO() as the base: memory_file = BytesIO() with zipfile.ZipFile(memory_file, ‘w’) as zf: files = result[‘files’] for individualFile in files: data = zipfile.ZipInfo(individualFile[‘fileName’]) data.date_time = … Read more

How to save binary data of zip file in Javascript?

Finally I got answer of my question: Here is the code: var xhr = new XMLHttpRequest();“POST”, baseURLDownload + “/service/report/QCPReport”, true); xhr.setRequestHeader(“Content-type”,”application/json”); xhr.setRequestHeader(“Access-Control-Allow-Origin”, “*”); xhr.onreadystatechange = function() { if (xhr.readyState == 4 && xhr.status == 200) { // alert(“Failed to download:” + xhr.status + “—” + xhr.statusText); var blob = new Blob([xhr.response], {type: … Read more

How to zip multiple files using only .net api in c#

With the release of the .NET Framework 4.5 this is actually a lot easier now with the updates to System.IO.Compression which adds the ZipFile class. There is a good walk-through on codeguru; however, the basics are in line with the following example: using System.Collections.Generic; using System.IO; using System.IO.Compression; using System.IO.Compression.FileSystem; namespace ZipFileCreator { public static … Read more

zip file and avoid directory structure

The zipfile.write() method takes an optional arcname argument that specifies what the name of the file should be inside the zipfile I think you need to do a modification for the destination, otherwise it will duplicate the directory. Use :arcname to avoid it. try like this: import os import zipfile def zip(src, dst): zf = … Read more

Create zip file from byte[]

After a little more playing around and reading I was able to figure this out. Here is how you can create a zip file (archive) with multiple files without writing any temporary data to disk: using (var compressedFileStream = new MemoryStream()) { //Create an archive and store the stream in memory. using (var zipArchive = … Read more

Using System.IO.Packaging to generate a ZIP file

let me google this for you -> first link using System; using System.IO; using System.IO.Packaging; namespace ZipSample { class Program { static void Main(string[] args) { AddFileToZip(“”, @”C:\Windows\Notepad.exe”); AddFileToZip(“”, @”C:\Windows\System32\Calc.exe”); } private static void AddFileToZip(string zipFilename, string fileToAdd, CompressionOption compression = CompressionOption.Normal) { using (Package zip = System.IO.Packaging.Package.Open(zipFilename, FileMode.OpenOrCreate)) { string destFilename = … Read more