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

[4.0.0.beta1] Uploading an image with an optimized image field throws 400 error #323

Closed
Nellyaa opened this issue Apr 8, 2022 · 1 comment
Labels

Comments

@Nellyaa
Copy link

Nellyaa commented Apr 8, 2022

Describe the bug

Just tried out ImageOptimize 4.0.0-beta.1 on Craft 4.0.0-beta4. Trying to upload an image on the asset page to an asset volume that has an optimized Images field fails. The loading bar never disappears and the console throws an error.
Uploading works fine if the asset volume doesn't have an optimized images field.
Removing the field, then uploading images and then reapplying the field again works as well, and after adding it, transforms will be generated as expected.

To reproduce

Steps to reproduce the behaviour:

  1. Add an optimized images field to an asset volume
  2. Go to asset page and choose an image to upload to the volume with the field
  3. Loading bar and spinner never disappears, console logs error as seen in screenshot

Expected behaviour

Image gets uploaded and ImageOptimize transforms generated :)

Screenshots

Unbenannt-2

Versions

  • Plugin version: ImageOptimize 4.0.0-beta.1
  • Craft version: Craft 4.0.0-beta4
[HTTP 400 – Bad Request](http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#400) – [yii\web\BadRequestHttpException](http://www.yiiframework.com/doc-2.0/yii-web-badrequesthttpexception.html)
No file was uploaded
1. in /var/www/vendor/craftcms/cms/src/controllers/AssetsController.phpat line 177
168169170171172173174175176177178179180181182183184185186     * @return Response
     * @throws BadRequestHttpException for reasons
     * @since 3.4.0
     */
    public function actionUpload(): Response
    {
        $uploadedFile = UploadedFile::getInstanceByName('assets-upload');
 
        if (!$uploadedFile) {
            throw new BadRequestHttpException('No file was uploaded');
        }
 
        $folderId = (int)$this->request->getBodyParam('folderId') ?: null;
        $fieldId = (int)$this->request->getBodyParam('fieldId') ?: null;
 
        if (!$folderId && !$fieldId) {
            throw new BadRequestHttpException('No target destination provided for uploading');
        }
 
2. craft\controllers\AssetsController::actionUpload()
3. in /var/www/vendor/yiisoft/yii2/base/InlineAction.php at line 57– call_user_func_array([craft\controllers\AssetsController, 'actionUpload'], [])
4. in /var/www/vendor/yiisoft/yii2/base/Controller.php at line 178– [yii\base\InlineAction::runWithParams](http://www.yiiframework.com/doc-2.0/yii-base-inlineaction.html#runWithParams()-detail)(['p' => 'admin/actions/assets/upload'])
5. in /var/www/vendor/yiisoft/yii2/base/Module.php at line 552– [yii\base\Controller::runAction](http://www.yiiframework.com/doc-2.0/yii-base-controller.html#runAction()-detail)('upload', ['p' => 'admin/actions/assets/upload'])
6. in /var/www/vendor/craftcms/cms/src/web/Application.php at line 301– [yii\base\Module::runAction](http://www.yiiframework.com/doc-2.0/yii-base-module.html#runAction()-detail)('assets/upload', ['p' => 'admin/actions/assets/upload'])
295296297298299300301302303304305306307     * @param string $route
     * @param array $params
     * @return Response|null The result of the action, normalized into a Response object
     */
    public function runAction($route, $params = []): ?BaseResponse
    {
        $result = parent::runAction($route, $params);
 
        if ($result === null || $result instanceof Response) {
            return $result;
        }
 
        $response = $this->getResponse();
7. in /var/www/vendor/craftcms/cms/src/web/Application.php at line 625– craft\web\Application::runAction('assets/upload', ['p' => 'admin/actions/assets/upload'])
619620621622623624625626627628629630631        if ($request->getIsActionRequest()) {
            $route = implode('/', $request->getActionSegments());
 
            try {
                Craft::debug("Route requested: '$route'", __METHOD__);
                $this->requestedRoute = $route;
                return $this->runAction($route, $_GET);
            } catch (Throwable $e) {
                $this->_unregisterDebugModule();
                if ($e instanceof InvalidRouteException) {
                    throw new NotFoundHttpException(Craft::t('yii', 'Page not found.'), $e->getCode(), $e);
                }
                throw $e;
8. in /var/www/vendor/craftcms/cms/src/web/Application.php at line 280– craft\web\Application::_processActionRequest(craft\web\Request)
274275276277278279280281282283284285286                    throw new ForbiddenHttpException();
                }
            }
        }
 
        // If this is an action request, call the controller
        if (($response = $this->_processActionRequest($request)) !== null) {
            return $response;
        }
 
        // If we’re still here, finally let Yii do its thing.
        try {
            return parent::handleRequest($request);
9. in /var/www/vendor/yiisoft/yii2/base/Application.php at line 384– craft\web\Application::handleRequest(craft\web\Request)
10. in /var/www/web/index.php at line 12– [yii\base\Application::run](http://www.yiiframework.com/doc-2.0/yii-base-application.html#run()-detail)()
6789101112// Load shared bootstrap
require dirname(__DIR__) . '/bootstrap.php';
 
// Load and run Craft
/** @var craft\web\Application $app */
$app = require CRAFT_VENDOR_PATH . '/craftcms/cms/bootstrap/web.php';
$app->run();
$_GET = [
    'p' => 'admin/actions/assets/upload',
];

$_COOKIE = [
    '08b50206495ab19261c35e647aeb027a_username' => '0eb2b1de38f4a73129f8612b2ef4e6b7a1cbcc8435832166c4d9f1e1f0941f52a:2:{i:0;s:41:"08b50206495ab19261c35e647aeb027a_username";i:1;s:7:"nellyaa";}',
    'CraftSessionId' => '69d10d181dad85485e07ee55375e4291',
    '08b50206495ab19261c35e647aeb027a_identity' => '0315be87332815964f05f2d59a5865a67e62804b679f4d4ef8fb33065f9e369ba:2:{i:0;s:41:"08b50206495ab19261c35e647aeb027a_identity";i:1;s:162:"[1,"[\\"EW49lGQ21s2zjJLPuVLqvtb37HF6701iiFq27cCsW08PhnJhCFvK9FshJyHD4fykaqi9pZPDH15TfqG_QSIeAlttvVigCXh6PeS4\\",null,\\"8e5a577e33f5bc3f7099260165cd35c7\\"]",1209600]";}',
    'CRAFT_CSRF_TOKEN' => '5b31d18d390e36b67abf01f9dca07022b88cf8a8ccaba9c654a51271a743d8cda:2:{i:0;s:16:"CRAFT_CSRF_TOKEN";i:1;s:147:"i16aMy_rB3Lh6ZhUdX3Z4i6Jnfq_TTn_8tjm9gWr|763e0d115c256c249b01cef3badd3bfae41c94d391a6be4c931312e4c3238a81i16aMy_rB3Lh6ZhUdX3Z4i6Jnfq_TTn_8tjm9gWr|1";}',
];

$_SESSION = [
    'a50e111d5f13061b3bc1c20c2a9c215d__flash' => [],
    '08b50206495ab19261c35e647aeb027a__token' => 'EW49lGQ21s2zjJLPuVLqvtb37HF6701iiFq27cCsW08PhnJhCFvK9FshJyHD4fykaqi9pZPDH15TfqG_QSIeAlttvVigCXh6PeS4',
    '08b50206495ab19261c35e647aeb027a__id' => 1,
    '__authKey' => '["EW49lGQ21s2zjJLPuVLqvtb37HF6701iiFq27cCsW08PhnJhCFvK9FshJyHD4fykaqi9pZPDH15TfqG_QSIeAlttvVigCXh6PeS4",null,"8e5a577e33f5bc3f7099260165cd35c7"]',
    '__duration' => 1209600,
    'commerce_cart' => '015fc4829247c45a9b8fc0f18bd187a0',
    '08b50206495ab19261c35e647aeb027a__expire' => 1650653342,
    'a50e111d5f13061b3bc1c20c2a9c215d__auth_access' => [
        'saveAssets:10',
    ],
];
@Nellyaa Nellyaa added the bug label Apr 8, 2022
khalwat pushed a commit that referenced this issue Apr 8, 2022
…g accessed, which would cause image uploads to fail ([#323](#323))
@khalwat
Copy link
Contributor

khalwat commented Apr 8, 2022

Addressed in: a722a79

Fixed in release 4.0.0-beta.2 -> https://github.com/nystudio107/craft-imageoptimize/releases/tag/4.0.0-beta.2

@khalwat khalwat closed this as completed Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants