Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[imaging browser] Fix download of JSON, Bval and Bvec files when they are on s3 #8354

Conversation

cmadjar
Copy link
Collaborator

@cmadjar cmadjar commented Feb 2, 2023

Brief summary of changes

This fixes the error 404 users had when they tried to download a JSON, Bval or Bvec file hosted on S3 from the imaging browser.

Fixing this bug also resolved https://github.com/aces/HBCD/issues/227 as new API endpoints needed to be created for those files.

@cmadjar cmadjar added Bug PR or issue introducing/requiring bug fixes (not mutually exclusive with the Feature label) API PR or issue introducing/requiring modifications to the API code 24.0.0-bugs Issues or bug fix PRs that were raised during the testing of release 24.0.0 labels Feb 2, 2023
@cmadjar cmadjar requested a review from xlecours February 2, 2023 17:44
@@ -90,7 +90,11 @@ class Format extends Endpoint
$handler = new Format\Brainbrowser($this->_image);
break;
case 'thumbnail':
$handler = new Format\Thumbnail($this->_image);
case 'nifti':
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aren't thumbnails intended to be displayed inline?

(It looks like the code already had an attachment Content-Disposition, so I guess it doesn't matter..)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the thumbnail is mainly used to be displayed in the imaging browser but it was already available for download in the API and that is the file I used to base all the other classes so I kept it. @driusan does it answer your question?

Copy link
Contributor

@xlecours xlecours left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the $_image instance variable is not needed anymore. All the other places are using $this->_info

Copy link
Contributor

@xlecours xlecours left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Xavier is happy as well

@driusan
Copy link
Collaborator

driusan commented Feb 10, 2023

I'm so happy to hear that @xlecours!

if (!$info->isFile()) {
error_log('Thumbnail not found');
if (!$this->_info->isFile()) {
error_log("$this->_file_type file not found");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be using the PSR logger, not error_log

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@driusan could you elaborate on how to do that? Sorry I am not very versed in the PSR realm apparently...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NDB_Page includes a $this->logger which implements PSR-3 (https://www.php-fig.org/psr/psr-3/) which honours the config settings from the LORIS config. I think this endpoint bypasses NDB_Page, so you might need to copy the initialization from the NDB_Page constructor and then use ie $this->logger->notice("something") (or the appropriate log level)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would involve changing src/Http/Endpoint to use Psr\Log\LoggerAwareTrait; and add somehting like this in process.

$loris = $request->getAttribute('loris');
$loglevel = $loris->getConfiguration()
    ->getLogSettings()
    ->getRequestLogLevel();

$this->logger = new \LORIS\Log\ErrorLogLogger($loglevel);

if (!$info->isReadable()) {
error_log('Thumbnail exists but is not readable by webserver');
if (!$this->_info->isReadable()) {
error_log(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

if (!$info->isReadable()) {
error_log('Thumbnail exists but is not readable by webserver');
if (!$this->_info->isReadable()) {
$this->logger->notice(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be logged at the level of "error" log level.

See the different log level definitions in PSR-3. https://www.php-fig.org/psr/psr-3/

The database referencing a file that the server can't read seems more severe than a notice.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to error

@xlecours
Copy link
Contributor

I am even more happy now. :)

@driusan driusan merged commit 9276ffa into aces:24.1-release Feb 13, 2023
@ridz1208 ridz1208 added this to the 24.1.2 milestone Feb 14, 2023
zaliqarosli pushed a commit to zaliqarosli/Loris that referenced this pull request Mar 6, 2023
… are on s3 (aces#8354)

This fixes the error 404 users had when they tried to download a JSON, Bval or Bvec file hosted on S3 from the imaging browser.

Fixing this bug also resolved aces/HBCD#227 as new API endpoints needed to be created for those files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
24.0.0-bugs Issues or bug fix PRs that were raised during the testing of release 24.0.0 API PR or issue introducing/requiring modifications to the API code Bug PR or issue introducing/requiring bug fixes (not mutually exclusive with the Feature label)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants