zipfile

Django response that contains a zip file with multiple csv files

本秂侑毒 提交于 2019-12-21 22:55:28
问题 I have a algorithm that outputs a list of tuples which is ready to be written into a csv file. I'm trying to write 3 csv files (through StringIO so no writing to disk) and then zip them altogether. After that I want to attach that to the response of a django request. I'm not sure what's the most efficient way to do this. Should I use StringIO to store the 3 calls through my algo? Should I actually create the csv files first before zipping them? Can I directly use 1 zipfile call without the

ZipResourceFile cannot be resolved to a type

99封情书 提交于 2019-12-21 19:52:19
问题 I am trying to rewrite my App to work with APK Expansion files. I have been following the documentation here http://developer.android.com/google/play/expansion-files.html . I have downloaded the ... ... but when I added this code ... public static Uri getTrackUriFromZipFile ( int track ) { // Get a ZipResourceFile representing a specific expansion file ZipResourceFile expansionFile = new ZipResourceFile(filePathToMyZip); } ... I get the error message ZipResourceFile cannot be resolved to a

Confused about making a CSV file into a ZIP file in django

旧时模样 提交于 2019-12-21 05:56:43
问题 I have a view that takes data from my site and then makes it into a zip compressed csv file. Here is my working code sans zip: def backup_to_csv(request): response = HttpResponse(mimetype='text/csv') response['Content-Disposition'] = 'attachment; filename=backup.csv' writer = csv.writer(response, dialect='excel') #code for writing csv file go here... return response and it works great. Now I want that file to be compressed before it gets sent out. This is where I get stuck. def backup_to_csv

Flask: how to send a dynamically generate zipfile to the client

自闭症网瘾萝莉.ら 提交于 2019-12-21 04:28:22
问题 I am looking for a way to send a zipfile to the client that is generated from a requests response. In this example, I send a JSON string to a url which returns a zip file of the converted JSON string. @app.route('/sendZip', methods=['POST']) def sendZip(): content = '{"type": "Point", "coordinates": [-105.01621, 39.57422]}' data = {'json' : content} r = requests.post('http://ogre.adc4gis.com/convertJson', data = data) if r.status_code == 200: zipDoc = zipfile.ZipFile(io.BytesIO(r.content))

ZipInputStream.getNextEntry returns null on some zip files

╄→гoц情女王★ 提交于 2019-12-21 04:03:15
问题 I have a simple code to extract zip files, it was working just fine as expected but during my test I tried my code with some zip files (fonts, icons and templates I downloaded from internet) just to make sure it should extract any zip files provided, but its not working with some zip files, here is the minimized code to regenerate this issue: package com.test.mytest; import java.io.FileInputStream; import java.util.Enumeration; import java.util.zip.ZipEntry; import java.util.zip.ZipFile;

How to download a ZipFile from a dotnet core webapi?

不羁岁月 提交于 2019-12-20 04:34:11
问题 I am trying to download a zip file from a dotnet core web api action, but I can't make it work. I tried calling the action via POSTMAN and my Aurelia Http Fetch Client. I am able to create the ZipFile like I want it and store it on the system, but can't fix it so it returns the zipfile via the api. Use-case: User selects a couple of picture collections and clicks the download button. The ids of the picture collections gets send to the api and a zipfile is created which contains a directory

How to return multiple files in HttpResponse Django

 ̄綄美尐妖づ 提交于 2019-12-20 02:28:08
问题 I have been wracking my brains in this problem. Is there a way in django to serve multiple files from a single HttpResponse? I have a scenario where i am looping through a list of json and want to return all those as file form my admin view. class CompanyAdmin(admin.ModelAdmin): form = CompanyAdminForm actions = ['export_company_setup'] def export_company_setup(self, request, queryset): update_count = 0 error_count = 0 company_json_list = [] response_file_list = [] for pb in queryset.all():

archiving symlinks with python zipfile

五迷三道 提交于 2019-12-20 01:13:05
问题 I have a script that creates zip files of dirs containing symlinks. I was surprised to find that the zipfiles have zipped the targets of the links as opposed to the links themselves, which is what I wanted and expected. Anyone know how to get zipfile to zip the links? 回答1: zipfile doesn't appear to support storing symbolic links. The way to store them in a ZIP is actually not part of the format and is only available as a custom extension in some implementations. In particular, Info-ZIP's

How to extract zip file recursively in Python

安稳与你 提交于 2019-12-19 05:31:17
问题 I have a zip file which contains three zip files in it like this: zipfile.zip\ dirA.zip\ a dirB.zip\ b dirC.zip\ c I want to extract all the inner zip files that are inside the zip file in directories with these names (dirA, dirB, dirC). Basically, I want to end up with the following schema: output\ dirA\ a dirB\ b dirC\ c I have tried the following: import os, re from zipfile import ZipFile os.makedirs(directory) # where directory is "\output" with ZipFile(self.archive_name, "r") as archive:

How to extract zip file recursively in Python

帅比萌擦擦* 提交于 2019-12-19 05:30:17
问题 I have a zip file which contains three zip files in it like this: zipfile.zip\ dirA.zip\ a dirB.zip\ b dirC.zip\ c I want to extract all the inner zip files that are inside the zip file in directories with these names (dirA, dirB, dirC). Basically, I want to end up with the following schema: output\ dirA\ a dirB\ b dirC\ c I have tried the following: import os, re from zipfile import ZipFile os.makedirs(directory) # where directory is "\output" with ZipFile(self.archive_name, "r") as archive: