ls_salv1011's avatar

Problem Accessing Files Saved on Storage in Laravel with Flysystem

Versione Laravel: 8.81 Versione PHP: 7.4.27 Driver e versione del database: MySQL 8 league/flysystem: 1.1.9 Descrizione: I am facing a problem in the context of a Laravel application related to uploading and managing files through the built-in storage system (Filesystem). The problem manifests as follows:

Upload Operations and Generated Path:

The store method is used to save a file to the storage/app/imports directory. The path generated by the store method is correctly logged, indicating that the file was presumably saved with a hash name in the desired location. example of printed log [2024-11-22 12:29:25] prod.INFO: Path generato: imports/aWZzHU9JIQApMGomxFavQ1MI7fxWn7tnWqt29R5U.xlsx

When the code tries to access the saved file using the generated path, the system (flysystem) throws an exception. This implies that the file is not found or the path passed is not recognized correctly.

The path check ($path) seems correct, and the logs indicate that the file exists at the time of upload. However, the storage system throws an exception when trying to interact with the file. ` $file = $request->file('file'); $path = $file->store('imports'); $nome_file = $file->hashName(); $nome_file_no_ext = basename($nome_file, '.xlsx');

try {
    VoucherImport::dispatch($nome_file_no_ext, $request->id_account, $request->id_agenzia,$path);
} catch (\Throwable $th) {
    if ($th->getCode() == 999)
        return $this->getErrorResponse($th->getMessage());
    else throw $th;
}`

League\Flysystem\FileNotFoundException: File not found at path: imports/aWZzHU9JIQApMGomxFavQ1MI7fxWn7tnWqt29R5U.xlsx

0 likes
2 replies
deantedesco's avatar

Are you experiencing this issue on a development system or a production system?

The first thing that comes to mind is you have multiple instances/containers running that are storing/retrieving the file, but as the system is using local storage it is only getting stored on a single instance and therefore it isn't available on the other systems where you are trying to access the file.

Can you manually look on the file system to see if that file exists in storage/app/imports/?

Happy to help, but you might need to supply some further info about your setup.

Snapey's avatar

This error

League\Flysystem\FileNotFoundException: File not found at path: imports/aWZzHU9JIQApMGomxFavQ1MI7fxWn7tnWqt29R5U.xlsx

Is because you need to give it the FULL path. The above is relative to your storage/app folder, wich in turn is relative to the location of your project

Please or to participate in this conversation.