Skip to content
Advertisement

Laravel store Files from API with specific folder creation

My goal is create Laravel API to store Files, from VSTO POST request. But first need figure out how create unigue folders in laravel where to file store.

From VSTO sending POST with File and parameter id_message. How to set Laravel Controller to store file as storage/app/MyFiles/{id_message}/file, and parametr id_message wile file_path save to database table ?

FileController

class FileController extends Controller
{
    function fileUpload(Request $request)
    {

    $request->validate([
        'id_message' => 'required|min:6'
    ]);

    $input = $reguest->all();
    
    $result=$request->file('file')->store('MyFiles');
    return ["result"=>$result];

Update

for someone who need clue:

function fileUpload(Request $request)
{
    //$fileFromApi=storage_path('app/apiFiles/');
    $request->validate([
        'id_message' => 'required|min:6'
    ]);

    $input = $request->all();
    
    $idParameter = $request->id_message=$request->id_message;

    $result=$request->file('file')->store('MyFiles/'.$idParameter);
    return ["result"=>$result];

Advertisement

Answer

instead of store() you can use storeAs() try this:

$file = $request->file('file')->storeAs($filepath, $filename, $driver);
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement