Skip to content

Commit

Permalink
Fix drag shapefile to upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Bluesmile82 committed May 29, 2023
1 parent 9ddec35 commit b448914
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src/components/shape-file-uploader/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@ import { ReactComponent as AddShapeIcon } from 'icons/add_shape_icon.svg';
function ShapeFileUploader({ sizeWarning, view, onError, onSuccess }) {
const t = useT();

const { getRootProps, getInputProps, rootRef } = useDropzone({
onDrop: useCallback(() => {
featureCollectionFromShape(rootRef.current, view, onSuccess, onError);
const { getRootProps, getInputProps } = useDropzone({
onDrop: useCallback((files) => {
if (!files || !files[0]) {
console.error('No file provided');
return;
}

const formData = new FormData();
formData.append('file', files[0]);
featureCollectionFromShape(formData, view, onSuccess, onError);
}),
});

Expand Down
4 changes: 2 additions & 2 deletions src/utils/analyze-areas-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function createHashFromGeometry(geometry) {
return sha1(flatRings.toString());
}

export function featureCollectionFromShape(input, view, onSucces, onError) {
export function featureCollectionFromShape(body, view, onSucces, onError) {
const generateRequestParams = {
filetype: 'shapefile',
publishParameters: JSON.stringify({
Expand All @@ -45,7 +45,7 @@ export function featureCollectionFromShape(input, view, onSucces, onError) {
'https://www.arcgis.com/sharing/rest/content/features/generate',
{
query: generateRequestParams,
body: input,
body,
method: 'post',
responseType: 'json',
}
Expand Down

0 comments on commit b448914

Please sign in to comment.