0.2.9 • Published 1 year ago

@beaubus/single-file-upload-for-vue v0.2.9

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Simple single file upload with Drag'n'Drop for Vue2 and Vue3

A universal, modern upload input package that supports both Vue2 and Vue3. It features Drag'n'Drop functionality and is based on the Fetch API, supporting both POST and DELETE methods. This package is simple, lightweight, and easy to use.

npm.io

Demo

Installation

NPM

npm i @beaubus/single-file-upload-for-vue

CDN

<script src="https://unpkg.com/@beaubus/single-file-upload-for-vue/dist/min.js"></script>

Usage

import single_file_upload_for_vue from '@beaubus/single-file-upload-for-vue';

components: {
    'single-file-upload-for-vue': single_file_upload_for_vue
}

Wrap component with <div> as it takes all the space:

<div style="width: 120px; height: 120px">
    <single-file-upload-for-vue
        name="name_of_the_file_input"
        store_url="/url-to-backend-store"
        destroy_url="/url-to-backend-destroy"
        :headers="{'Accept': 'application/json'}"
        :loaded="{url: 'https://full-url-to-your-file.pdf', size: 56}"
        @complete="uploadComplete"
    ></single-file-upload-for-vue>
</div>

Backend

On the server side, you should handle POST and DELETE requests. DELETE url would have the file name at the end.

RequestReturn
POST{url: 'full-url', size: 0}
DELETE{result: true}

Laravel example:

// routes/web.php

Route::post('/upload', 'PrintableInvoicesController@uploadCustomInvoice');
Route::delete('/destroy/{file_name}', 'PrintableInvoicesController@destroyCustomInvoice');


// PrintableInvoicesController.php

public function uploadCustomInvoice(Request $request): array
{
    $path = $request->custom_invoice_file->store('folder');
    $url = asset('storage/' . $path);

    return [
        'url' => $url,
        'size' => \Storage::size($path),
    ];
}


public function destroyCustomInvoice(string $file_name): array
{
    return [
        'result' => \Storage::delete('folder/' . $file_name)
    ];
}

Styling

npm.io

Increase specificity and style it as you need:

div > .single-file-upload-for-vue {
    font-size: .75em;
    border: 2px dashed #dc5f00;
    background: #ffe484;
    border-radius: 20%;
}

Properties

NameTypeDefaultDescription
nameString'file_input'Name of the file input
store_urlString'/store-url'url for the POST request
destroy_urlString'/destroy-url'url for the DELETE request (file name would be appended to the end)
headersObjectRequest headers
loadedObjectAbsolute link to the loaded file (url) and size in bytes (size)
acceptStringA comma-separated list of one or more file types, or unique file type specifiers, describing which file types to allow

Emits

NameDescriptionPayload
completeUpload complete eventAbsolute link to the uploaded file and size in bytes: {url: 'link', size: 7}

License

The MIT License (MIT). Please see License File for more information.

0.2.9

1 year ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.5

2 years ago

0.2.4

3 years ago

0.2.3

3 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.14

4 years ago

0.1.13

4 years ago

0.1.12

4 years ago

0.1.11

4 years ago

0.1.10

4 years ago

0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.18

4 years ago

0.0.17

4 years ago

0.0.16

4 years ago

0.0.15

4 years ago

0.0.13

4 years ago

0.0.12

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago