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

@bkstar18/vue-ajax-uploader

v1.0.2

Published

A Vue plugin for ajax file upload (single file & multiple files selection)

Downloads

25

Readme

vue-ajax-uploader

A Vue plugin for the simple Ajax file uploading (single or multiple files selection). This plugin works well with any Laravel backend 5.5+.

1. Installation

npm install --save-dev @bkstar18/vue-ajax-uploader  

2. Requirement

  • This plugin requires Bootstrap 4.x and axios package
  • If you follow Laravel's standard setup for frontend, then all things are set out of the box. Otherwise, you may need to manually install axios and configure it to send X-CSRF-TOKEN for every request.

3. Integrate with Laravel backend

After installation, put the following code in resources/js/app.js:

import VueAjaxUploader from '@bkstar18/vue-ajax-uploader';  
Vue.use(VueAjaxUploader);  

Then, compile the frontend assets: npm run production or npm run dev.

In your upload view, for example: resources/views/upload.blade.php, you can use <bks123-file-input> element to render a ajax file upload input, as follows:

<bks123-file-input>Upload Files</bks123-file-input>

If you do not specify any attributes, then the plugin will use the following defaults:

  • input-name: file => name of the file input
  • input-id: file => DOM Id of the file input
  • input-class: '' => class of the file input
  • multiple: false => allow multiple files selection
  • progress-bar-color: bg-primary => bootstrap bg color of the progress bar
  • allowed-extensions: ['png', 'jpg', 'jpeg', 'mp4', 'doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx', 'txt', 'pdf'] => acceptable file extensions
  • upload-url: /upload => the backend URL for upload
  • batch-size: 5 => maximum number of files can be uploaded
  • max-size: 5242880 => maximum file size in bytes (<=> 5 MB)

An example for customizing the default behavior:

<bks123-file-input input-name="image" 
                   key="image"
                   input-class="form-control"
                   input-id="image-upload"
                   :multiple="true"
                   progress-bar-color="bg-success"
                   :allowed-extensions="['jpg', 'png', 'mp4']"
                   upload-url="/api/upload"
                   :batch-size="10"
                   :max-size="50*1024*1024">Upload Files</bks123-file-input>

Important Note:
The plugin expects to receive JSON response from the backend with success key in case of success or error key in case of error.

Sample structure of JSON responses are as follows:
a) Success response

{
    "success": "Successfully uploaded", // mandatory key
    ...  // other key that you may add
}

b) Error response

{
    "error": "Upload failed", // mandatory key
    ...  // other key that you may add
}

Example:

<?php
...
public function upload(Request $request, FileUpload $fileupload)
{
	$data = $fileupload->handle($request, 'image', ['allowedExtensions' => ['jpg', 'png', 'jpeg']]);
	if (!$data) {
		return response()->json(['error' => $fileupload->uploadError], 422);
	}

	// Save data to database

	return response()->json(['success' => "{$data['filename']} has been uploaded", 'data' => $data], 200);
}