Skip to content
On this page

Raw Image Uploader

After the image cropped, component <HcRawImageUploader /> return imageId.

An image uploader component is a software component that allows users to upload images.

The image uploader component consists of a user interface that allows users to select an image from their device. It also include features such as drag-and-drop functionality, file format validation, and progress indicators to provide feedback on the upload process.

When implementing an image uploader component, it is important to consider factors such as file size limits, supported file format. File size limits may be necessary to prevent users from uploading overly large files that could slow down the website or application.

How it's work

Here are steps for uploading an image in HcRawImageUploader:

  1. Choose the image: Select the image file that you want to upload to the system (or use drag-and-drop functionality for this). Ensure that the image meets the required size and format specifications.

  2. Generate the rendition: Uploading image to companition with one MAIN rendition. The height, width and aspect ratio of the image for this rendition are the same as in the original file.

  3. Generate the rendition: Generate the rendition by executing the appropriate command in the system. Wait for the system to finish generating the rendition.

  4. Create image item: Create image item with one MAIN rendition.

Usage

Before use HcRawImageUploader component you need to add uppy plugin in your project.

js
/* Uppy Instances */
import { Plugin, shallowRef } from 'vue';
import { Uppy } from '@uppy/core';
import { Gcp } from '@deeepvision/hope-component-kit';
import { IMAGE_UPLOADER_UPPY_KEY } from '@deeepvision/hope-component-kit';

export default {
  install(app) {
    const companionUrl = 'your companionUrl';
    const bucket = 'your bucket';

    if (!companionUrl) {
      throw new Error(`companionUrl wasn't set in env variables`);
    }

    if (!bucket) {
      throw new Error(`bucket wasn't set in env variables`);
    }

    const uppy = shallowRef<Uppy | null>(new Uppy({
      id: 'image-uploader',
      debug: true,
      autoProceed: true,
      allowMultipleUploadBatches: true,
      restrictions: {
        allowedFileTypes: ['image/*'],
      },
    }).use(Gcp, {
      limit: 2,
      companionUrl,
      bucket,
    }));

    app.provide(IMAGE_UPLOADER_UPPY_KEY, {
      default: uppy,
    });
  },
} as Plugin;

Several uppy instances and api in the project

If you have more that one uppy instance and need to save files on earch of them, you should provide additional uppy instances.

js
  app.provide(IMAGE_UPLOADER_UPPY_KEY, {
    default: uppy,
    exampleUppyId: exampleUppy,
    ...
  });

After that use prop uppyId to describe which uppy you want to use in the component.

There are cases where you use two or more api and need to save image in each of them. In this case you can use prop graphqlClientId and pass there ApolloClientId.

Basic usege

Use prop btn-text to customize button text in empty state. Use prop hide-tooltip to hide info icon. Use prop zoomable to show zoom action. Use prop optional to show delete action. Use prop downloadable to show download action.

<template>
  <ClientOnly>
    <div class="flex items-end">
      <HcRawImageUploader
        v-model="value1"
        label="Image uploader"
        class="!w-36 !h-36 !rounded-2xl flex-shrink-0"
      />
      <HcRawImageUploader
        v-model="value2"
        label="Zoomable"
        btn-text="Upload"
        class="!w-36 !h-36 !rounded-2xl ml-5 flex-shrink-0"
        zoomable
        hide-tooltip
      />
      <HcRawImageUploader
        v-model="value3"
        label="Optional and downloadable"
        btn-text="Upload"
        class="!w-36 !h-36 !rounded-2xl flex-shrink-0 ml-5"
        optional
        downloadable
      />
    </div>
  </ClientOnly>
</template>

<script lang="ts" setup>
import { ref } from 'vue';
import { HcRawImageUploader } from '@deeepvision/hope-component-kit';

const value1 = ref('');
const value2 = ref('');
const value3 = ref('');

</script>

Disabled state

Use prop disabled or readonly to change component state

<template>
  <ClientOnly>
    <div class="flex items-end">
      <HcRawImageUploader
        v-model="value1"
        label="Disabed"
        btn-text="Upload"
        class="!w-36 !h-36 !rounded-2xl flex-shrink-0"
        disabled
      />
      <HcRawImageUploader
        v-model="value2"
        label="Readonly"
        btn-text="Upload"
        class="!w-36 !h-36 !rounded-2xl ml-5 flex-shrink-0"
        readonly
      />
    </div>
  </ClientOnly>
</template>

<script lang="ts" setup>
import { ref } from 'vue';
import { HcRawImageUploader } from '@deeepvision/hope-component-kit';

const value1 = ref('');
const value2 = ref('');
</script>

Error state

Add Boolean prop error or prop errorMsg for show error state

<template>
  <ClientOnly>
    <div class="flex items-end">
      <HcRawImageUploader
        v-model="value1"
        label="Error"
        btn-text="Upload"
        class="!w-36 !h-36 !rounded-2xl flex-shrink-0"
        error
      />
      <HcRawImageUploader
        v-model="value2"
        label="Error message"
        btn-text="Upload"
        class="!w-36 !h-36 !rounded-2xl flex-shrink-0 ml-5"
        error-msg="This field is required"
      />
      <HcRawImageUploader
        v-model="value3"
        label="Error and disabled"
        btn-text="Upload"
        class="!w-36 !h-36 !rounded-2xl flex-shrink-0 ml-5"
        error
        disabled
      />
    </div>
  </ClientOnly>
</template>

<script lang="ts" setup>
import { ref } from 'vue';
import { HcRawImageUploader } from '@deeepvision/hope-component-kit';

const value1 = ref('');
const value2 = ref('');
const value3 = ref('');
</script>

Props

PropertyType Values Description Default
modelValueStringStringbinding value (imageId)
btnTextStringStringuploader button text
roundedBooleanBooleanwhether component is roundedfalse
sizeStringmiddlelargecomponent size.middle
optionalBooleanBooleanwhether show delete buttonfalse
downloadableBooleanBooleanwhether show download buttonfalse
zoomableBooleanBooleanwhether show zoom buttonfalse
maxFileSizeNumberNumberallowed max file size for downloaded file5000000
disabledBooleanBooleanwhether component is disabledfalse
readonlyBooleanBooleanwhether component is readonlyfalse
errorBooleanBooleanwhether component has error and change it's style to that state.false
errorMsgStringStringerror message
labelStringStringlabel text
hideTooltipBooleanBooleanwhether show info tooltipfalse
graphqlClientIdStringStringgraphql clientId for queries and mutationsdefault
uppyIdStringStringid one of provided uppy instancesdefault

Slots

PropertyType Values Description Default
empty-statedragging - booleancustomize uploader empty state
empty-state-inner-customize uploader empty inner state
empty-state-tooltip-customize tooltip content
label-suffix-customize label suffix content

Events

PropertyType Values Description Default
update:model-valueFunctionimageId - stringtriggers when image uploaded
focusFunctionevent - FocusEventtriggers when ImageUploader focuses
blurFunction-triggers when ImageUploader blurs

Created by DeepVision Software.