Sen Sen - 5 months ago 20
PHP Question

Php-opencloud Object Storage download file, GuzzleStream, how to>

How do I download my object using Php-opencloud?
http://docs.os.php-opencloud.com/en/latest/services/object-store/v1/objects.html

In the documentation I see.

$stream = $openstack->objectStoreV1()
->getContainer('{containerName}')
->getObject('{objectName}')
->download();


It return GuzzleStream Object.
How do I popup a screen for prompting file download?

When I Try to echo the stream, it returns garbled text
%PDF-1.4 %�쏢 5 0 obj .........

Sen Sen
Answer

I just add a header and flush the buffer

header('Content-Disposition: attachment; filename=' . basename($request));
    header("Content-Type: ".$mime);
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . $file->getSize());
    ob_clean();
    flush();

    echo $file;

$file is my stream

Comments