Apr 21, 2020
0
Level 1
Help fixing Zip Folder download error
Controller
public function bulkDownload(BulkDownloadMediaRequest $request)
{
$medias = [];
foreach ($request->media as $id)
{
//object of media
$media = $this->medias->find($id);
$medias[] = $media;
//if i want cd url for a media then I can get by doing $media->getUrl()
}
return MediaStream::create('eventName.zip')->addMedia($medias);
}
ajax call
var media = this.selectedItemIds;
$.ajax({
type: 'GET',
url: '{{ route("myroute.bulkDownload") }}',
contentType: 'application/json; application/octet-stream',
responseType: 'blob',
data: {media:media},
success: function (res, status, xhr) {
var headers = xhr.getResponseHeader('content-disposition');
var fileName = headers.toString().split('=')[1].toString().replace(/\"/g, '');
var blob = new Blob([res]);
var link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = fileName;
link.click();
}
})
When I try to open downloaded zip folder it gives me `Unable to expand 'eventName.zip. into "downloads". (Error 79 - Inappropriate file type or format.)
Please or to participate in this conversation.