Skip to content

Commit

Permalink
fix download stream
Browse files Browse the repository at this point in the history
  • Loading branch information
killua-eu committed Jan 14, 2024
1 parent 66b2857 commit 0ae13ed
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions glued/Controllers/ServiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
use mysqli_sql_exception;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Glued\Classes\Exceptions\AuthTokenException;
use Glued\Classes\Exceptions\AuthJwtException;
use Glued\Classes\Exceptions\AuthOidcException;
use Glued\Classes\Exceptions\DbException;
use Glued\Classes\Exceptions\TransformException;
//use Slim\Psr7\Stream;
//use Slim\Psr7\Factory\StreamFactory;
use Nyholm\Psr7\Factory\Psr17Factory;
use Ramsey\Uuid\Uuid;

class ServiceController extends AbstractController
Expand Down Expand Up @@ -514,11 +512,14 @@ public function links_r1(Request $request, Response $response, array $args = [])

if (file_exists($file)) {
$mime = mime_content_type($file);
$fileStream = fopen($file, 'rb');
$stream = (new Psr17Factory())->createStreamFromResource($fileStream);

$response = $response
->withHeader('Content-Type', $mime)
->withHeader('Content-Disposition', "attachment;filename=\"{$res['obj']}.{$mime}\"")
->withHeader('Content-Length', filesize($file));
readfile($file);
$response->getBody()->write($stream->getContents());
return $response;
} else { $data['status'] = 'Not found'; return $response->withJson($data)->withStatus(404); }
}
Expand Down

0 comments on commit 0ae13ed

Please sign in to comment.