0

I have a strange issue when trying to upload files with dropzone.js. I wanted to upload all files in public > file-archive folder. If the folder doesn't exist, the request passes fine, though I don't see file uploaded.

public function store(Request $request)
{
    $this->createArchiveFolder();
    Storage::disk('archive')->put($request->file->getClientOriginalName() . $request->file->getClientOriginalExtension(), $request->file);
}

protected function createArchiveFolder()
{
    if (!file_exists(public_path() . '/file-archive'))
        \File::makeDirectory(public_path() . '/file-archive', 777);
}

After this, the folder gets created (I tried creating it manually also and commenting out the create method). If I try to upload a file when folder exists, I get this:

enter image description here

My route:

Route::post('file-archive', 'FileArchiveController@store')->name('file-archive.store');

and my front end part:

{!! Form::open(['route' => 'file-archive.store', 'class' => 'dropzone', 'files'=>true, 'id'=>'real-dropzone']) !!}

<div class="dz-message"></div>

<div class="fallback">
    <input name="file" type="file" multiple/>
</div>

<div class="dropzone-previews" id="dropzonePreview"></div>

<h4 style="text-align: center;color:#428bca;">Drop files in this area <span
            class="glyphicon glyphicon-hand-down"></span></h4>

{!! Form::hidden('csrf-token', csrf_token(), ['id' => 'csrf-token']) !!}

{!! Form::close() !!}
jedrzej.kurylo
  • 39,591
  • 9
  • 98
  • 107
Norgul
  • 4,613
  • 13
  • 61
  • 144

1 Answers1

0

Your best option is to click in that error and then select the response tab to see what the error is.

Since you're getting an error 403, I think the problem is with the token, you're creating a field called csrf-token but Laravel expects _token.

For future forms you can use the helper {!! csrf_field() !}} which will create the hidden input for you.

Lloople
  • 1,827
  • 1
  • 17
  • 31