🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

vue-crop-upload

Package Overview
Dependencies
Maintainers
0
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-crop-upload

VueCropUpload is a Vue 3 component that provides image uploading functionality with built-in cropping capabilities. It allows users to select an image file, crop it, and upload it to a specified URL.

3.0.5
latest
Source
npm
Version published
Weekly downloads
0
-100%
Maintainers
0
Weekly downloads
 
Created
Source

Vue Image Uploader

VueCropUpload is a Vue 3 component that provides image uploading functionality with built-in cropping capabilities. It allows users to select an image file, crop it, and upload it to a specified URL.

This component uses Cropper.js, a powerful JavaScript image cropping library.

Features

  • Vue 3 component for image uploading with built-in cropping functionality
  • Integrates Cropper.js for powerful image cropping capabilities
  • Customizable file type restrictions
  • Configurable maximum file size limit
  • Custom headers and additional data support for upload requests
  • Adjustable aspect ratio for image cropping
  • Progress tracking for upload process
  • Error handling for various upload scenarios
  • Responsive design suitable for various screen sizes
  • Easy to integrate with existing Vue 3 projects
  • Lightweight and performant
  • Fully typed for TypeScript projects

Installation

npm install vue-crop-upload
import { VueCropUpload } from 'vue-crop-upload'
import 'vue-crop-upload/dist/style.css'

Usage

<template>
  <VueCropUpload
    :url="uploadUrl"
    :extensions="allowedExtensions"
    :headers="headers"
    :data="additionalData"
    :maxFileSize="maxSize"
    :aspectRatio="cropAspectRatio"
    @error="handleError"
    @success="handleSuccess"
  >
    <template #default="{ activator, progress, loading }">
      <button @click="activator" :disabled="loading">
        {{ loading ? `Uploading (${progress}%)` : 'Upload Image' }}
      </button>
    </template>
  </VueCropUpload>
</template>

<script>
export default {
  methods: {
    handleSuccess({ data }) {
      console.log('Upload successful:', data)
    },
    handleError(error) {
      console.error('Upload error:', error.message)
    }
  }
}
</script>

Props

PropTypeDefaultDescription
urlstring-The URL to upload the image to (required)
extensionsstring'png,jpg,gif,jpeg'Comma-separated list of allowed file extensions
headersobject{}Additional headers to send with the upload request
dataobject{}Additional data to send with the upload request
rationumber-Aspect ratio for image cropping
maxFileSizenumber-Maximum file size in bytes

Events

EventPayloadDescription
successresponseEmitted when the upload is successful
errorerrorEmitted when an error occurs during upload or validation

Slots

The component provides a default slot that exposes the following properties:

  • activator: Function to trigger the file selection dialog
  • progress: Number representing the upload progress (0-100)
  • loading: Boolean indicating whether an upload is in progress

Use these properties to create your custom upload button UI.

Development

To set up the project for development:

  • Clone the repository
  • Install dependencies: npm install
  • Start the development server: npm run dev

Types

interface ErrorEvent {
  type: 'INVALID_FILE_EXTENSION' | 'FILE_SIZE_EXCEEDED' | 'UPLOAD_ERROR' | 'INVALID_FILE_TYPE';
  message: string;
}

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Dependencies

This project uses the following major dependencies:

  • Vue 3: The progressive JavaScript framework
  • Cropper.js: A simple JavaScript image cropper

License

This project is licensed under the MIT License.

Credits

  • Image cropping functionality is provided by Cropper.js, created by Chen Fengyuan.

  • This is a Vue 3 implementation inspired by the concept of vue-image-crop-upload, but built from the ground up for Vue 3

FAQs

Package last updated on 17 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts