calvinmetcalf / shapefile-js

Convert a Shapefile to GeoJSON. Not many caveats.
http://calvinmetcalf.github.io/shapefile-js/
714 stars 228 forks source link

Error while loading a zip file ("can't read the data...") #168

Closed maxschmi closed 2 years ago

maxschmi commented 2 years ago

Hallo, I'm trying to use this package to enable the users of my website to upload a zipped .shp file. For this purpose i have a file-Input where the user can choose the file.

out of this fileList i then get the arrayBuffer and hand that to the shp function. But when i do this I get the following error: grafik

This is my code: let inputFile = document.getElementById("uploadFile"); let buffer = inputFile.files[0].arrayBuffer(); shp.parseZip(buffer).then((geojson) =>console.log(geojson));

Where am I wrong or is there another problem?

Notice: I'm on a localhost server for developing purposes.

maxschmi commented 2 years ago

Okay I solved the problem by myself. The problem was that I did not enter the result of the buffer-Promise but the Promise to the shp function. So my new code is: let inputFile = document.getElementById("uploadFile"); inputFile.files[0].arrayBuffer().then((bufferResult) => { shp.parseZip(bufferResult).then((geojson) => console.log(geojson)) });