You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Double "Content-Type" headers in ApiController::getThumbnail #12712
This is the code which returns a thumbnail in the Files' ApiController
$preview = new Preview('', 'files', urldecode($file), $x, $y, true);
echo($preview->showPreview('image/png'));
return new DownloadResponse(urldecode($file).'.png', 'image/png');
showPreview() already returns headers, so the client never gets the second header
I'm not sure what echo() around that void function is supposed to do?
Solutions
Remove the DownloadResponse and fix the headers of OC_Image::show() if better ones are needed.
Use OC_Preview::getPreview(), add headers locally via OCP\Response and header() and push that to the client
$preview = new Preview('', 'files', urldecode($file), $x, $y, true);
$preview->showPreview('image/png');
} catch (\Exception $e) {
return new JSONResponse('File not found.', Http::STATUS_NOT_FOUND);
And I get this:
Error PHP Cannot modify header information - headers already sent by (output started at /var/www/owncloud/lib/private/image.php:249) at /var/www/owncloud/lib/private/appframework/app.php#116 2015-03-22T20:17:16+00:00
Error PHP Cannot modify header information - headers already sent by (output started at /var/www/owncloud/lib/private/image.php:249) at /var/www/owncloud/lib/private/appframework/app.php#104 2015-03-22T20:17:16+00:00
Error PHP Cannot modify header information - headers already sent by (output started at /var/www/owncloud/lib/private/image.php:249) at /var/www/owncloud/lib/private/appframework/app.php#104 2015-03-22T20:17:16+00:00
@enoch85 - Ah, yes, my bad... It's in a controller, so you we can't do it this way because it's the one sending the headers.
Let's try again, by replacing the original
$preview = new Preview('', 'files', urldecode($file), $x, $y, true);
echo($preview->showPreview('image/png'));
return new DownloadResponse(urldecode($file).'.png', 'image/png');
I'm not sure if more headers are required and this might be fragile, in case bad previews are sent to the class, but if it works, it wouldn't be worst than the original solution.
Error PHP Call to undefined method OC\Preview::data() at /var/www/owncloud/apps/files/controller/apicontroller.php#53 2015-03-22T20:54:59+00:00
Error PHP Call to undefined method OC\Preview::data() at /var/www/owncloud/apps/files/controller/apicontroller.php#53 2015-03-22T20:54:59+00:00
Error PHP Call to undefined method OC\Preview::data() at /var/www/owncloud/apps/files/controller/apicontroller.php#53
Error PHP Call to a member function getPreview() on a non-object at /var/www/owncloud/apps/files/controller/apicontroller.php#53 2015-03-22T21:16:41+00:00
Error PHP Undefined variable: previewData at /var/www/owncloud/apps/files/controller/apicontroller.php#53 2015-03-22T21:16:41+00:00
Error PHP Call to a member function getPreview() on a non-object at /var/www/owncloud/apps/files/controller/apicontroller.php#53 2015-03-22T21:16:40+00:00
Error PHP Undefined variable: previewData at /var/www/owncloud/apps/files/controller/apicontroller.php#53 2015-03-22T21:16:40+00:00
Activity
oparoz commentedon Dec 8, 2014
@georgehrke - You might know what's best to do in this situation.
enoch85 commentedon Feb 24, 2015
any update on this?
rullzer commentedon Mar 16, 2015
I ran into a similar situation with the avatars. I'll prepare a PR that fixes this.
oparoz commentedon Mar 22, 2015
@enoch85 - On stable8, you could try simply replacing this
with this
enoch85 commentedon Mar 22, 2015
So now the code looks like this:
And I get this:
enoch85 commentedon Mar 22, 2015
@oparoz Any other suggestion?
oparoz commentedon Mar 22, 2015
@enoch85 - Ah, yes, my bad... It's in a controller, so you we can't do it this way because it's the one sending the headers.
Let's try again, by replacing the original
with this
I'm not sure if more headers are required and this might be fragile, in case bad previews are sent to the class, but if it works, it wouldn't be worst than the original solution.
oparoz commentedon Mar 22, 2015
Just added another header
enoch85 commentedon Mar 22, 2015
Gives
enoch85 commentedon Mar 22, 2015
@oparoz we are getting there. ;) Next move?
7 remaining items
enoch85 commentedon Mar 22, 2015
@oparoz Yes, it was Githubs fault.
Get this now:
Any suggestion?
oparoz commentedon Mar 22, 2015
Argh... I'm not using the IDE and it shows...
enoch85 commentedon Mar 22, 2015
Haha, yes now the error is gone, but it doesn't show any previews. :/
What to do?
oparoz commentedon Mar 22, 2015
Check the network tab in your browser's debugger (F12). If you're getting 412 errors, it means some headers are missing.
enoch85 commentedon Mar 22, 2015
Browsers debugger? I´m testing with the Android app, not Chrome.
oparoz commentedon Mar 22, 2015
In case it's the headers, try this
The Response class is smart enough to be able to replace a header.
Even when using Android, you can type the thumbnail URL in a browser. You get the URL from the owncloud log
enoch85 commentedon Mar 22, 2015
Ok, so I can see the previews in the browser with both of your solutions - with no errors, but not with the Android app. @tobiasKaminsky
oparoz commentedon Mar 22, 2015
OK, I won't be able to help you there then... Hopefully someone else will be able to offer a fix.
enoch85 commentedon Mar 22, 2015
OK, so this is a working patch for the browser:
Thanks for helping me debugging!
oparoz commentedon Mar 22, 2015
Thanks for testing 36 versions of the patch ;)
MorrisJobke commentedon Mar 24, 2015
@rullzer is this fixed with #14919 ?
rullzer commentedon Mar 24, 2015
It should be. But @oparoz please confirm.
rullzer commentedon Apr 13, 2015
So I assume the PR fixed this. Please reopen if not.