0

皆さん、おはようございます。

私の質問は簡単です。Flysystem (Symfony 上) を使用して、(DigitalOcean 経由で) S3 からリソースを回復します。ダウンロード用にユーザーに返却できるようにしたいと思います。これが私のコードです:

    $client = new S3Client([
        'credentials' => [
            'key'    => '',
            'secret' => '',
        ],
        'region' => '',
        'version' => 'latest',
        'endpoint' => 'https://ams3.digitaloceanspaces.com',
    ]);

    $adapter = new AwsS3Adapter($client, '');

    $filesystem = new Filesystem($adapter);
    $filename = 'file.png';
    $stream = $filesystem->readStream('file.png');
    $contents = stream_get_contents($stream);
    fclose($stream);

    $response = new Response($stream);
    $disposition = $response->headers->makeDisposition(
        ResponseHeaderBag::DISPOSITION_ATTACHMENT,
        $filename
    );
    $response->headers->set('Content-Disposition', $disposition);

    return $response;

=> ファイルが壊れています...

何か案は?大変お世話になりました。ギヨーム

更新テキストファイルで確認すると、ファイルの内容を受け取りますが、ヘッダーが付いています:

HTTP/1.1 200 OK
Date: Thu, 27 Sep 2018 06:59:35 GMT
Server: Apache/2.4.29 (Ubuntu)
Vary: Authorization,Accept-Encoding
Cache-Control: no-cache, private
Content-Disposition: attachment; filename=toto.png
Link: <http://localhost/api/public/api/docs.jsonld>; rel="http://www.w3.org/ns/hydra/core#apiDocumentation"
Content-Length: 517
Content-Type: text/html; charset=UTF-8

ファイルコンテンツのみをダウンロードし、すべてのファイルタイプをダウンロードするアイデアはありますか? いつもありがとう、ギョーム

4

0 に答える 0