Giter Site home page Giter Site logo

Comments (2)

MaatwebsiteSupport avatar MaatwebsiteSupport commented on May 3, 2024

Hey

As far as I know, it's not possible to set the download headers when doing an ajax request.

from laravel-excel.

daraghoshea avatar daraghoshea commented on May 3, 2024

Hi, I am looking at using the jquery file download plugin (http://johnculviner.com/jquery-file-download-plugin-for-ajax-like-feature-rich-file-downloads/) to mimic the effect of ajax downloading.

The plugin's method is dependent upon a header being sent when the file is being downloaded, but the LaravelExcelWriter::_download() method does not allow for the headers to be altered.

Ideally, an event could be fired allowing for the headers to be adjusted prior to being sent to LaravelExcelWriter::_setHeaders()

Perhaps the following code change could be considered:

Current

$this->_setHeaders(array(
        'Content-Type'        => $this->contentType,
        'Content-Disposition' => 'attachment; filename="' . $this->filename . '.' . $this->ext . '"',
        'Expires'             => 'Mon, 26 Jul 1997 05:00:00 GMT', // Date in the past
        'Last-Modified'       => Carbon::now()->format('D, d M Y H:i:s'),
        'Cache-Control'       => 'cache, must-revalidate',
        'Pragma'              => 'public'
    ));

Suggested

$headers = new Illuminiate\Support\Collection(array(
        'Content-Type'        => $this->contentType,
        'Content-Disposition' => 'attachment; filename="' . $this->filename . '.' . $this->ext . '"',
        'Expires'             => 'Mon, 26 Jul 1997 05:00:00 GMT', // Date in the past
        'Last-Modified'       => Carbon::now()->format('D, d M Y H:i:s'),
        'Cache-Control'       => 'cache, must-revalidate',
        'Pragma'              => 'public'
    ));

Event::fire('maatwebsite.excel.headers', $headers);

$this->_setHeaders( $headers->toArray() );

It's a great package, but unfortunately I probably couldn't use it without this flexibility. Thanks.

from laravel-excel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.