Search code examples
node.jsmultipartform-dataform-datajsziphere-maps-rest

Getting a bad request 400 when trying to upload zipped wkt file to here-maps rest api


We have a problem with the fleet.ls.hereapi.com when uploading a new layer for geofencing.

const myId = 'MYLAYER'; // just a id to check
zip.file('data.wkt', `NAME\tWKT\n${myId}\t${wkt}`);
const content = await zip.generateAsync({ type: 'nodebuffer' });
const formData = new FormData();
formData.append('zipfile', content);
await axios.post(config.HERE_MAPS_UPLOAD_ENDPOINT, formData, {
  headers: {
    'content-type': 'multipart/form-data',
  },
  params: {
    apiKey: config.HERE_MAPS_REST_API_KEY,
    layer_id: myId,
  },
});

We get a bad request without a message and do not know what the problem is. The same implementation works in the Frontend (with 'blob' as zip type). Is there a parameter to get a better error message from the api? We got the instructions how to implement it from this tutorial: https://www.youtube.com/watch?v=Ayw9GcS1V-8 and as I mentioned it works fine in the frontend. Also it works if I write a file in node and upload it via curl. Thank you for any help in advance!

Edit: I'm getting the following issue from the API: 'Multipart should contain exactly one part but contains 0'


Solution

  • I fixed it! The problem was that the api needed a filename for the form data. This filename can be provided as third parameter as described here.

    So I basically changed formData.append('zipfile', content); to formData.append('zipfile', content, zipfile.zip); and it worked.

    Hope this will help somebody in the future!