question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not able to use Image Editor in react Dashboard

See original GitHub issue

Hi All,

Greatly appreciate any help - I cannot get the Image Editor to show.

I’m using the DashboardModal react component. Also tried the Dashboard react component.

I’m able to successfully upload the file. The webcam module works. I just cannot edit/crop the image before upload. I don’t see the edit icon next to the thumbnail.

import React, { useEffect, useMemo, useState } from 'react';
import PropTypes from 'prop-types';
import Uppy from '@uppy/core';
import Webcam from '@uppy/webcam';
import XHRUpload from '@uppy/xhr-upload';
import ImageEditor from '@uppy/image-editor';
import { DashboardModal } from '@uppy/react';
import '@uppy/core/dist/style.css';
import '@uppy/dashboard/dist/style.css';
import '@uppy/webcam/dist/style.css';
import '@uppy/image-editor/dist/style.css';
import { apiBaseUrl } from '../../constants';
import { getAccessToken } from '../../authService';

const Uploader = ({ id }) => {
  const [isModalOpen, setIsModalOpen] = useState(false);

  const uppy = useMemo(() => {
    return new Uppy({
      id,
      allowMulipleUploads: false,
      logger: Uppy.debugLogger,
      restrictions: {
        maxFileSize: 15 * 1024 * 1024,
        maxNumberOfFiles: 1,
        allowedFileTypes: ['.jpg', '.jpeg', 'gif', '.png'],
      },
    })
      .use(XHRUpload, {
        id: 'XHRUploader',
        endpoint: `${apiBaseUrl}/media`,
        formData: true,
        fieldName: 'file',
        headers: {
          authorization: `Bearer ${getAccessToken()}`,
        },
        limit: 1,
        getResponseData(responseText) {
          console.log(responseText);
          return {
            fileName: responseText,
          };
        },
      })
      .use(ImageEditor, {
        id: 'ImageEditor',
        quality: 0.8,
        cropperOptions: {
          viewMode: 1,
          background: false,
          autoCropArea: 1,
          responsive: true,
        },
      })
      .use(Webcam, {
        id: 'Webcam',
        modes: ['picture'],
      })
      .on('upload-success', (file, response) => {
        console.log('response.status', response.status);
        console.log('response.body', response.body);
      });
  }, [id]);

  useEffect(() => {
    return () => uppy.close();
  }, [uppy]);

  const handleClose = () => {
    setIsModalOpen(false);
  };

  const handleOpen = () => {
    setIsModalOpen(true);
  };

  return (
    <div>
      <button onClick={handleOpen}>Upload some music</button>
      <DashboardModal
        uppy={uppy}
        closeModalOnClickOutside
        open={isModalOpen}
        onRequestClose={handleClose}
        plugins={['Webcam', 'ImageEditor']}
      />
    </div>
  );
};

Uploader.propTypes = {
  id: PropTypes.string,
};

export default Uploader;

Thanks, Nim

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

16reactions
getup8commented, Aug 16, 2020

Just to add, I think it’d be nice to actually have a setting that auto-directs users to the image editor upon file selection. This may be a small use case, but in the case of just uploading a single, say, user profile photo that you want to be a square, it would be a nice user experience.

4reactions
hunterbectoncommented, Aug 9, 2020

I figured it out! After searching the Dashboard docs you have to pass in the metaFields in order to enable the edit button. My component now looks like this:

return (
        <div>
            <button onClick={handleOpen}>Upload profile</button>
            <DashboardModal
                uppy={uppy}
                closeModalOnClickOutside
                open={isModalOpen}
                onRequestClose={handleClose}
                plugins={['Instagram', 'ImageEditor']}
                metaFields={[
                    { id: 'name', name: 'Name', placeholder: 'File name' },
                ]}
            />
        </div>
    )
Read more comments on GitHub >

github_iconTop Results From Across the Web

Not able to upload Image with ImageField in EDIT mode for ...
Using React Admin I am creating a dashboard for one of my clients and I have a requirement where I have to add...
Read more >
Image editor With React - DEV Community ‍ ‍
Hello guys today i want to show you an image editor app created with React js. It's not an advance image editor
Read more >
Image Editor - Uppy
@uppy/image-editor allows users to crop, rotate, zoom and flip images that are added to Uppy. Designed to be used with the Dashboard UI...
Read more >
Build and Deploy a React Admin Dashboard App ... - YouTube
Every web developer needs to build a React Admin Dashboard Application. Learn how to create the best and most modern one simply by...
Read more >
React Image Upload Made Easy - YouTube
In React apps, you often have to upload images or files. Learn how easy it actually is to do that!Join the full React...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found