Requirements:
- CKAN 2.3+ (Resource view support required)
- Python 2.6 or 2.7
- zipfile Python module (standard library)
- Network access for externally hosted ZIP files
Installation:
Activate CKAN virtualenv:
. /usr/lib/ckan/default/bin/activate
Install extension:
pip install ckanext-zippreview
Or from source:
git clone https://github.com/datagovau/ckanext-zippreview.git
cd ckanext-zippreview
python setup.py develop
Install dependencies:
pip install -r dev-requirements.txt
Add plugin to ckan.plugins in production.ini:
ckan.plugins = … zip_view …
Add to default views (optional but recommended):
ckan.views.default_views = … zip_view …
This automatically creates ZIP previews for new ZIP resources.
Restart CKAN:
sudo service apache2 reload
Configuration:
Default Views (Automatic Preview Creation):
Add zip_view to default views for automatic preview generation:
ckan.views.default_views = image_view text_view recline_view zip_view
When enabled, ZIP preview automatically created for:
- Resources with .zip extension
- Resources with format = “ZIP”
- Resources with MIME type application/zip
Manual View Creation:
If not using default_views, create views manually:
- Go to resource page
- Click “Manage” → “Views”
- Click “New view”
- Select “ZIP Preview” from view types
- Configure and save
Usage:
Automatic Preview:
- Upload or link to ZIP file as resource
- Set format to “ZIP” or use .zip extension
- ZIP preview automatically created (if in default_views)
- Preview shows file listing with:
- File/folder names
- File sizes
- Directory structure
- Nested folders (expandable)
Manual Preview Creation:
- Navigate to resource
- Click “Manage” button
- Select “Views” tab
- Click “New view”
- Choose “ZIP Preview”
- Save view
Preview Display Features:
File Listing:
- Hierarchical directory structure
- File names and paths
- File sizes (human-readable: KB, MB, GB)
- Folder expansion/collapse
- Total archive size
- Number of files
Supported ZIP Features:
- Standard ZIP archives
- Nested directories
- Large files (size displayed)
- Compressed and uncompressed
Limitations:
- Only shows file listing (no content preview)
- Cannot extract individual files via interface
- Large archives may take time to process
- Password-protected ZIPs not supported
External ZIP Files:
Works with externally hosted ZIP files:
- Add resource with external ZIP URL
- Set format to “ZIP”
- Extension downloads and previews remote ZIP
- Requires network access from CKAN server
Security Considerations:
External Files:
- CKAN server downloads external ZIPs
- Ensure trusted sources only
- Monitor disk usage
- Consider timeout settings
ZIP Bombs:
- Extension reads ZIP header only
- No full extraction occurs
- Safe against most ZIP bomb attacks
- Large listings may impact performance
Development:
Clone repository:
git clone https://github.com/datagovau/ckanext-zippreview.git
cd ckanext-zippreview
Install for development:
python setup.py develop
pip install -r dev-requirements.txt
Create test.ini from template
Run tests:
pytest –ckan-ini test.ini
Test with sample ZIP files:
- Create test resources with various ZIP structures
- Test nested directories
- Test large file listings
- Test external URLs
Customization:
Customize Preview Template:
Override templates/zippreview/view.html in your theme:
{% extends “base.html” %}
{% block primary_content %}
Archive Contents
{% for file in files %}
-
{{ file.name }}
{{ file.size }}
{% endfor %}
{% endblock %}
Customize Styling:
Add CSS for ZIP preview:
.zip-preview {
border: 1px solid #ddd;
padding: 20px;
border-radius: 4px;
}
.zip-file-list {
list-style: none;
font-family: monospace;
}
.zip-file-list li {
padding: 5px 0;
border-bottom: 1px solid #eee;
}
.file-name {
flex: 1;
}
.file-size {
color: #666;
font-size: 0.9em;
}
Troubleshooting:
Preview not appearing:
- Verify zip_view plugin is enabled
- Check resource format is set to “ZIP”
- Ensure .zip file extension
- Verify resource view created
- Check CKAN version >= 2.3
External ZIP not loading:
- Verify URL is accessible from CKAN server
- Check firewall/network rules
- Test URL manually: wget
- Review CKAN logs for errors
- Check disk space for download
Large archives slow:
- Listing very large archives takes time
- Consider timeout settings
- Monitor server resources
- Optimize archive structure if possible
Empty preview:
- Verify ZIP file is valid
- Test ZIP locally: unzip -l file.zip
- Check for corrupted archives
- Review error logs
Permission errors:
- Verify CKAN has read access to files
- Check temporary directory permissions
- Ensure web server user can access storage
Performance Optimization:
Caching:
- Cache file listings for large archives
- Store preview data in resource extras
- Refresh on resource update
Timeouts:
- Set reasonable timeouts for external downloads
- Limit archive processing time
- Provide fallback for large files
Resource Limits:
- Consider max archive size
- Limit number of files displayed
- Paginate very large listings
Best Practices:
Resource Metadata:
- Always set format to “ZIP”
- Use descriptive resource names
- Add description of archive contents
- Document archive structure
File Organization:
- Use clear directory structure in ZIPs
- Include README files in archives
- Use descriptive file names
- Avoid deeply nested structures
External Resources:
- Verify external URLs are stable
- Monitor for broken links
- Consider local copies for critical data
- Document external dependencies
User Guidance:
- Explain what preview shows (listing only)
- Provide download link for full archive
- Document how to extract files
- Include usage instructions
Use Cases:
Data Archives:
- Multiple CSV files in one package
- Let users see what’s inside before downloading
- Preview structure of data collections
Geographic Data:
- Shapefiles (multiple components in ZIP)
- Show file structure
- Help users identify correct files
Document Collections:
- Multiple PDFs or reports
- Preview document list
- Help users find specific documents
Code Repositories:
- Source code archives
- Show directory structure
- Help developers navigate
Integration:
With Other View Types:
Combine with other previews:
ckan.views.default_views = image_view text_view recline_view pdf_view zip_view
- Images: Preview individual image files
- Text: Preview README or text files
- PDF: Preview documentation
- ZIP: Preview archive structure
With Data Extraction:
Extend to extract specific files:
class EnhancedZipView(ZipPreviewPlugin):
def can_extract_file(self, filename):
# Allow extracting specific file types
return filename.endswith((‘.csv’, ‘.json’, ‘.txt’))
def extract_file(self, archive, filename):
# Extract and preview individual file
return archive.read(filename)
Development Status: Beta (4)
License: AGPL v3.0 or later
Keywords: CKAN, zip, compressed, archive, preview, resource view
Developer: Alex Sadleir / data.gov.au
Related Extensions:
- ckanext-pdfview: PDF file preview
- ckanext-geoview: Geospatial data preview
- ckanext-textview: Text file preview
- ckanext-archiver: Archive downloading and checking