cqpCow 8 months ago
parent
commit
aaf6677696
1 changed files with 4 additions and 0 deletions
  1. 4 0
      app/Http/Controllers/Api/FileUploadController.php

+ 4 - 0
app/Http/Controllers/Api/FileUploadController.php

@@ -5,6 +5,7 @@ use App\Exports\MyExport;
 use App\Service\FileUploadService;
 use App\Service\OssService;
 use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Storage;
 use PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions\F;
 
 //文件上传
@@ -29,6 +30,9 @@ class FileUploadController extends BaseController
         $date = $date->format('Y-m-d');
         $path = storage_path() . "/app/public/" . FileUploadService::tmp_dir . '/' . $date. '/' . $file_name;
 
+        // 返回一个错误响应或默认图片
+        if (! Storage::exists($path)) return response()->json(201, "File not exists");
+
         return response()->file($path);
     }