首页 > 解决方案 > Laravel Excel::Import using google cloud storage 突然停止工作,报错:mkdir(): No such file or directory

问题描述

一段时间以来,我一直在使用 Laravel 导入上传到谷歌云存储的文件。在不更改任何代码的情况下,以下调用突然停止工作。

Excel::import($importer, $document->path, env('GOOGLE_STORAGE_DISK', 'local'), $fileType);

从导入方法跟踪的返回错误如下。

"message": "mkdir(): No such file or directory",
    "exception": "ErrorException",
    "file": "/workspace/vendor/maatwebsite/excel/src/Files/TemporaryFileFactory.php",
    "line": 52,
    "trace": [
        {
            "function": "handleError",
            "class": "Illuminate\\Foundation\\Bootstrap\\HandleExceptions",
            "type": "->"
        },
        {
            "file": "/workspace/vendor/maatwebsite/excel/src/Files/TemporaryFileFactory.php",
            "line": 52,
            "function": "mkdir"
        },
        {
            "file": "/workspace/vendor/maatwebsite/excel/src/Reader.php",
            "line": 398,
            "function": "makeLocal",
            "class": "Maatwebsite\\Excel\\Files\\TemporaryFileFactory",
            "type": "->"
        },
        {
            "file": "/workspace/vendor/maatwebsite/excel/src/Reader.php",
            "line": 99,
            "function": "getReader",
            "class": "Maatwebsite\\Excel\\Reader",
            "type": "->"
        },
        {
            "file": "/workspace/vendor/maatwebsite/excel/src/Excel.php",
            "line": 146,
            "function": "read",
            "class": "Maatwebsite\\Excel\\Reader",
            "type": "->"
        },
        {
            "file": "/workspace/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php",
            "line": 261,
            "function": "import",
            "class": "Maatwebsite\\Excel\\Excel",
            "type": "->"
        },
        {
            "file": "/workspace/app/Http/Controllers/ImportController.php",
            "line": 175,
            "function": "__callStatic",
            "class": "Illuminate\\Support\\Facades\\Facade",
            "type": "::"
        },

这是在 TemporaryFileFactory.php 中引发错误的行

if (!file_exists($this->temporaryPath) && !mkdir($concurrentDirectory = $this->temporaryPath) && !is_dir($concurrentDirectory)) {

我根本不知道如何开始解决这个问题。由于我没有进行任何代码更改,我只能假设某个库的新版本是罪魁祸首。但是我尝试在我的 composer.json 中对旧库版本进行硬编码

"maatwebsite/excel": "3.1.19",

并运行 composer install ,似乎没有什么区别。任何关于尝试解决这个问题的方向的任何线索都将不胜感激。

标签: excellaravelimportgoogle-cloud-storage

解决方案


我决定改用“/tmp”,
为此,我需要发布和更改 config/excel.php

php artisan vendor:publish –provider="Maatwebsite\Excel\ExcelServiceProvider"

编辑配置/excel.php

'local_path'          => '/tmp',

推荐阅读