Edgewall Software
Modify

Opened 17 years ago

Closed 17 years ago

Last modified 17 years ago

#1504 closed defect (duplicate)

Support for downloading files in zip format (format=zip)

Reported by: PBruin Owned by: Jonas Borgström
Priority: high Milestone:
Component: version control/browser Version: devel
Severity: normal Keywords:
Cc: peter.bruin@… Branch:
Release Notes:
API Changes:
Internal Changes:

Description

I have been having some problems with downloading files from the Browser as none of the mime types have been specified in the repository I use. To make it easier to download files I have added a Zip Archive format next to the Original Format at the bottom of the file view in the Browser. This will download the file in zip format.
I also used the mime_type instead of the node.content_type for the 'format=raw' to prevent those ugly errors when trying to view a file has no mime_type defined in svn.
Do you think this could be added to the trunk?

Index: Browser.py
===================================================================
--- Browser.py	(revision 1579)
+++ Browser.py	(working copy)
@@ -174,7 +174,7 @@

         if req.args.get('format') == 'raw':
             req.send_response(200)
-            req.send_header('Content-Type', node.content_type)
+            req.send_header('Content-Type', mime_type)
             req.send_header('Content-Length', node.content_length)
             req.send_header('Last-Modified', util.http_date(node.last_modified))
             req.end_headers()
@@ -185,7 +185,27 @@
                 if not chunk:
                     break
                 req.write(chunk)
+        elif req.args.get('format') == 'zip':
+            req.send_header('Content-Type', 'application/zip')
+            req.send_header('Content-Disposition',
+                            'filename=%s.zip' % node.name )
+            req.end_headers()

+            try:
+                from cStringIO import StringIO
+            except ImportError:
+                from StringIO import StringIO
+            from zipfile import ZipFile, ZipInfo, ZIP_DEFLATED
+
+            buf = StringIO()
+            zipfile = ZipFile(buf, 'w', ZIP_DEFLATED)
+            zipinfo = ZipInfo()
+            zipinfo.filename = node.name
+            zipinfo.date_time = time.gmtime(node.last_modified)[:6]
+            zipinfo.compress_type = ZIP_DEFLATED
+            zipfile.writestr(zipinfo, node.get_content().read())
+            zipfile.close()
+            req.write(buf.getvalue())
         else:
             # Generate HTML preview
             content = util.to_utf8(node.get_content().read(DISP_MAX_FILE_SIZE),
@@ -205,6 +225,10 @@
             req.hdf['file.raw_href'] = raw_href
             add_link(req, 'alternate', raw_href, 'Original Format', mime_type)

+            add_link(req, 'alternate',
+                     self.env.href.browser(node.path, rev=rev and node.rev, format='zip'),
+                     'Zip Archive', 'application/zip' )
+
             req.display('browser.cs')

Attachments (0)

Change History (2)

comment:1 by Christopher Lenz, 17 years ago

Resolution: duplicate
Status: newclosed

This is basically a duplicate of #238.

comment:2 by Matthew Good, 17 years ago

Milestone: 0.9
Priority: lowhigh

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jonas Borgström.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Jonas Borgström to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.