2.4.0 • Published 2 years ago

laravel-file-uploader v2.4.0

Weekly downloads
5
License
ISC
Repository
github
Last release
2 years ago

Laravel File Uploader

This plugin register vue component to upload files using laravel-media-library.

Uploader

Requirements

You should install ahmed-aliraqi/laravel-media-uploader composer package to work successfully.

Installation

npm i laravel-file-uploader --save-dev  

Basic Usage

<div id="app">  
    <file-uploader  
            :unlimited="true"  
            collection="avatars"  
            name="media"  
            :tokens="{{ json_encode(old('media', [])) }}"  
            label="Upload Avatar"  
            notes="Supported types: jpeg, png,jpg,gif"
            :display-validation-messages="true"  
    ></file-uploader>  
</div>  
  
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>  
<script src="https://cdn.jsdelivr.net/npm/laravel-file-uploader"></script>  
<script>  
  new Vue({  
    el: '#app'  
  })  
</script>  

Configure With Laravel Ui

// app.js  
  
import FileUploader from 'laravel-file-uploader';  
  
Vue.use(FileUploader);  

Usage

<file-uploader :media="{{ $user->getMediaResource('avatars') }}"  
               :unlimited="true"  
               collection="avatars"  
               name="media"  
               :tokens="{{ json_encode(old('media', [])) }}"  
               label="Upload Avatar"  
               notes="Supported types: jpeg, png,jpg,gif"  
               accept="image/jpeg,image/png,image/jpg,image/gif"  
></file-uploader>  

Working with images

You optimize images size before uploading by adding max-{width|height} attribute and will upload the image as a base64 file:

<file-uploader :media="{{ $user->getMediaResource('avatars') }}"  
               :unlimited="true"  
               collection="avatars"  
               name="media"  
               max-width="800"  
               max-height="800"  
               :tokens="{{ json_encode(old('media', [])) }}"  
               label="Upload Avatar"  
               notes="Supported types: jpeg, png,jpg,gif"  
               accept="image/jpeg,image/png,image/jpg,image/gif"  
</file-uploader>  
Attributes
AttributeRuleTypeDescription
nameoptional - default: mediastringthe name of tokens fields
mediaoptional - default: []arrayused to display an existing files
unlimitedoptional - default:falsebooleanupload unlimited files - if let it false will not be multiple select
maxoptional - default:12intthe maximum uploaded files - if 1 will not me multiple select
acceptoptional - default: *stringthe accepted mime types
formoptional - default: falsestringthe form id of the uploaded media
notesoptional - default nullstringthe help-block that will be displayed under the files
labeloptional - default nullstringthe label of the uploader
collectionoptional - default defaultstringthe media library collection that the file will store in
tokensoptional - default: []arraythe recently uploaded files tokens, used to display recently uploaded files in validation case
nameoptional - default: nullarraythe input name of the uploader
max-widthoptional - default: 1200stringThe maximum width of uploaded image
max-heightoptional - default: 1200stringThe maximum height of uploaded image
display-validation-messagesoptional - default: falsebooleanUsed for displaying validation messages
Use With Vue Or SPA Applications
<file-uploader   
    name="media"  
    v-model="tokens"  
></file-uploader>  
  
<script>  
    new Vue({  
        el: '#app',  
        data() {  
            return {  
                tokens: []  
            }  
        }  
    })  
</script>  
Events
  • beforeUpload
  • complete
<file-uploader   
   label="Upload File"   
   @beforeUpload="handleBeforeUpload()"  
   @complete="handleComplete()"  
></file-uploader>  
  • upload-error
<file-uploader   
   label="Upload File"   
   @beforeUpload="handleBeforeUpload()"  
   @upload-error="errorHandler"
></file-uploader>  
<script>  
    new Vue({  
        el: '#app',  
        methods: {  
		  errorHandler(error) {  
			  console.log(error.file) // the file object  
			  console.log(error.response) // the error response from the server  
			  console.log(error.status) // the error status code from the server  
		  }  
		}
    })  
</script> 
File Preview Component

This component used to preview uploaded media (images, audios, videos).

<file-preview :media="{{ $user->getMediaResource('avatars') }}"></file-preview>  

Note:
Do not forget to store the laravel csrf token in an HTML meta tag:

<meta name="csrf-token" content="{{ csrf_token() }}">  
2.4.0

2 years ago

2.3.0

3 years ago

2.2.0

3 years ago

2.1.1

3 years ago

2.1.0

3 years ago

2.0.6

3 years ago

2.0.5

3 years ago

2.0.4

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.10

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.2

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago