{"record":{"id":"b50ce92ddc9d3d61","repo":"octobercms/october","slug":"there-is-no-file-attached-to-import","errorCode":null,"errorMessage":"There is no file attached to import!","messagePattern":"There is no file attached to import!","errorType":"exception","errorClass":"ApplicationException","httpStatus":null,"severity":"error","filePath":"modules/cms/models/ThemeImport.php","lineNumber":113,"sourceCode":"        $this->attributes['themeName'] = $theme->getConfigValue('name', $theme->getDirName());\n        $this->attributes['dirName'] = $theme->getDirName();\n        $this->attributes['theme'] = $theme;\n    }\n\n    /**\n     * import\n     */\n    public function import($theme, $data = [], $sessionKey = null)\n    {\n        @set_time_limit(3600);\n\n        $this->theme = $theme;\n        $this->fill($data);\n\n        try {\n            $file = $this->uploaded_file()->withDeferred($sessionKey)->first();\n            if (!$file) {\n                throw new ApplicationException('There is no file attached to import!');\n            }\n\n            $themePath = $this->theme->getPath();\n            $tempPath = temp_path() . '/'.uniqid('oc');\n            $zipName = uniqid('oc');\n            $zipPath = temp_path().'/'.$zipName;\n\n            File::put($zipPath, $file->getContents());\n\n            if (!File::makeDirectory($tempPath)) {\n                throw new ApplicationException('Unable to create directory '.$tempPath);\n            }\n\n            Zip::extract($zipPath, $tempPath);\n\n            if (File::isDirectory($tempPath.'/meta')) {\n                $this->copyDirectory($tempPath.'/meta', $themePath.'/meta');\n            }","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/octobercms/october/blob/b608633a7e8922487d91a8161499020121c3b3bf/modules/cms/models/ThemeImport.php#L95-L131","documentation":"ThemeImport::import() resolves the attached archive through the uploaded_file deferred relation with the provided $sessionKey. If no file model is returned, it throws - meaning the import ran without a zip ever being attached, or the deferred binding was invisible because the session key was wrong, missing, or the upload session expired.","triggerScenarios":"Submitting the theme import form without selecting a file; calling import($theme, $data, $sessionKey) with a $sessionKey that differs from the one the fileupload widget used when binding the file; a deferred binding flushed or session lost between upload and import.","commonSituations":"Custom AJAX import handlers that forget to forward the widget session key; user leaving the import wizard open past session lifetime; the file upload failing silently (size limits) so the relation stays empty.","solutions":["Attach the zip in the import form and confirm the upload widget finished successfully before clicking Import.","When calling import() programmatically, pass the exact session key the upload used - the same value the fileupload widget reports as sessionKey.","Guard before importing: $import->uploaded_file()->withDeferred($sessionKey)->first() must return a file.","If the session expired, restart the wizard from upload."],"exampleFix":"// before: wrong key - deferred binding invisible, import throws\n$themeImport->import($theme, $data, $otherKey);\n\n// after: reuse the key the file was deferred-bound under\n$themeImport->import($theme, $data, $fileWidget->sessionKey);","handlingStrategy":"validation","validationCode":"$file = $themeImport->uploaded_file()->withDeferred($sessionKey)->first();\nif (!$file) {\n    // show 'select a zip file' validation error before import() runs\n}","typeGuard":null,"tryCatchPattern":"try {\n    $themeImport->import($theme, $data, $sessionKey);\n} catch (ApplicationException $e) {\n    // re-prompt the upload step; typically a lost/wrong session key\n}","preventionTips":["Mark the file field required in the import form.","Forward the fileupload widget's sessionKey through every AJAX handler in the wizard.","Restart the wizard if the session expires - deferred bindings die with it."],"tags":["file-upload","deferred-binding","theme-import","session-key"],"backgroundTag":"missing-file-upload","analyzedSha":"b608633a7e8922487d91a8161499020121c3b3bf","analyzedAt":"2026-08-21T04:24:57.515Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}