如何将通过x-sendfile发送的文件视为GET响应


How to view files sent through x-sendfile as GET response

我使用的是Slim Framework 3。这是我的代码:

....
    $response = $response->withStatus(200)
                        ->withHeader('X-Sendfile', $path)
                        ->withHeader('Content-Type', $contentType)
                        ->withHeader('Content-disposition:', 'attachment; filename=' . $fileName);
                    return $response;
....

当通过邮递员使用时,我看到了图像。但是,如何使用响应在html页面上显示图像/视频/音频?

由于x-sendfile返回了整个文件,因此该文件实际上是一个blob。因此,我在javascript中将ajax请求的responseType设置为blob。我在"使用Javascript显示Blob"中遵循@AdamZ的回答,一切都正常。