简体   繁体   中英

Laravel Storage facade with S3 - cannot download pdf files, get 'Incorrectly nested style tag found' exception

I am running Laravel 5.3. When I try to download one of our csv files from S3:

Storage::disk('s3')->get('files/contract.csv');

...it works fine. But any time I try to get a pdf file from the same S3 location:

Storage::disk('s3')->get('files/contract.pdf');

I get this exception:

InvalidArgumentException with message 'Incorrectly nested style tag found.'

This happens for ALL pdf files, even pdf files that I grab from the net and put on S3 strictly for testing purposes. Is this a bug or am I doing something incorrectly?

By the way, this exception comes from the vendor/symfony/console/Formatter/OutputFormatterStyleStack class:

public function pop(OutputFormatterStyleInterface $style = null)
{
    if (empty($this->styles)) {
        return $this->emptyStyle;
    }

    if (null === $style) {
        return array_pop($this->styles);
    }

    foreach (array_reverse($this->styles, true) as $index => $stackedStyle) {
        if ($style->apply('') === $stackedStyle->apply('')) {
            $this->styles = array_slice($this->styles, 0, $index);

            return $stackedStyle;
        }
    }

    throw new InvalidArgumentException('Incorrectly nested style tag found.');
}

Update:

Just to clarify the issue. When I run the test directly on the web app server like so:

Route::get('test', function() {
    return Storage::disk('s3')->get('files/document.pdf');
});

It works. It also works if it is inside a command that I execute from the shell.

The way my site actually works is this: the web server makes a request to a worker box which is running a laravel work daemon and it appears that the error I described above is due to it running in a daemon. Both the console command and the web route work fine. Weird.

So the issue all along was that the csv is text data and pdf is binary, which for some reason, prevented my app from returning the pdf data. My solution was to base64 encode the pdf data, after which I was able to return it without issues.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM