npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

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

v0.2.9

Published

Universal (Vue2 and Vue3) modern upload input with Drag'n'Drop support, based on the Fetch Api (POST and DELETE methods). Simple and lightweight.

Downloads

84

Readme

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.

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.

| Request | Return
| --- | ---
| 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

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

| Name | Type | Default | Description
| --- | --- | --- | ---
| name | String | 'file_input' | Name of the file input | store_url | String | '/store-url' | url for the POST request
| destroy_url | String | '/destroy-url' | url for the DELETE request (file name would be appended to the end) | headers | Object | | Request headers | loaded | Object | | Absolute link to the loaded file (url) and size in bytes (size) | accept | String | | A comma-separated list of one or more file types, or unique file type specifiers, describing which file types to allow

Emits

| Name | Description | Payload | --- | --- | --- | complete | Upload complete event | Absolute 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.