New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support bulk downloading assets as a ZIP archive #6606
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat! But this definitely won't work with S3 or other non-local filesystems.
Also, we just merged #6599 which simplifies the action and removes the need for a javascript bit. You could probably just do the zipping from within the download
method of the action. You could return a response that streams the zip file.
Ah OK, could this still be added for non-S3 users? Should I add a check for that?
Ha, for some reason I thought that had been merged before I started, oh well. I've refactored this and it makes things so much simpler! Only other change I had to make was to the content-disposition regex in |
Sorry yeah I meant the approach should be adjusted so it'll work for any driver. It looks like you can pass in file contents as strings instead of paths to the zip package. So this might work: $zip = Zip::create('assets.zip');
$items->each(function ($asset) use ($zip) {
$zip->add($asset->contents(), $asset->basename());
});
return $zip->response(); Try that? It's probably better if the assets can be streamed too (using |
Fancy stuff! Just tested on S3 asset container and it works great! 💅 The only negative I can think of is that it's slower over S3 because it has to get the file contents over the api first for each individual asset. I don't see this as a problem for a handful of assets, but I wonder if this will timeout the request if you select too many assets and/or extremely large assets? |
Probably fine for now and we can add streaming support later. |
That said, I just tested 50 decently sized images and it still worked! Downloaded them from S3 in under 20 seconds. |
@jacksleight you're the man!! |
This PR adds bulk asset download support.
I had something similar knocking about from an addon I never finished, so thought I'd PR this as it came up in ideas.
Uses the Zip Stream library, so the archive doesn't have to be saved to disk first.
Closes statamic/ideas#855