Atef95's avatar

Dropzone js Server responded with 0 code.

Hey guys

I'm using vue dropzone js to upload my images but I'm getting this error below

Server responded with 0 code.

I cannot connect to my api..

this is my component code

<template>
    <div>
           <section class="content" style="margin-top:20px;">
            <div class="row">
                <div class="container-fluid">

                   <div class="box box-primary">
            <div class="box-header with-border">
              <h3 class="box-title">Importer une régie publicitaire</h3>
            </div>
            <!-- /.box-header -->
            <!-- form start -->
            <form role="form">
              <div class="box-body">
                <div class="form-group">
                  <vue-dropzone ref="myVueDropzone" id="dropzone" :options="dropzoneOptions"></vue-dropzone>
                </div>
          
            
              </div>
          

            </form>
          </div>

              
                </div>

            </div>

        </section>
    </div>
</template>
 
<script>
import vue2Dropzone from 'vue2-dropzone'
import 'vue2-dropzone/dist/vue2Dropzone.min.css'

    export default {
           components: {
         vueDropzone: vue2Dropzone
        },

        mounted() {
            console.log('Component mounted.')
        },
        data() {
            return {
                    dropzoneOptions: {
                    url: '/api/ads/upload',
                    thumbnailWidth: 150,
                    maxFilesize: 3,
                    addRemoveLinks: true,
                    dictDefaultMessage: "<i class='fa fa-cloud-upload'></i>&nbsp;Importer une photo",
                    dictRemoveFile: 'Retirer',
                    dictFileTooBig:'Fichier volumineux',
                    acceptedFiles: "image/jpeg,image/png",
                       headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      }
      }


            }
        }
    }
</script>

this is my api in laravel

<?php

Route::group(['module' => 'General', 'middleware' => ['auth:api'], 'namespace' => 'App\Modules\General\Controllers\api'], function() {

Route::post('/api/ads/upload', 'GeneralController@handleUploadAdvertisement');

});

 public function handleUploadAdvertisement(Request $request)
    {
  
 dd($request->all());
    }

0 likes
3 replies
bobbybouwmann's avatar

The auth:api middleware here requires you to be authenticated in some way. This can be Laravel Passport or a simple token, depending on your setup. Because of that, it will never get past that endpoint.

Atef95's avatar

@bobbybouwmann it's fixed and it was so silly... Adblocker extension was blocking it because I think the endpoint has the keyword "ads" so when I turned it off it worked...

Please or to participate in this conversation.