Programmatically uploading (geo)JSON files throws mimetype error #2204
Replies: 3 comments
-
Hey @stefgootzen this is very interesting. I have never run into this myself but I can see how this package would definitely cause some issues with text-based files. We can likely swap out this dependency to support text-based files. I will convert this to a Discussion and then add it to our Roadmap. If you'd like to help here, we would happily accept a PR. Looks like the package is only used in 3 places within our code so if we can find a suitable replacement, we can certainly swap it out. Otherwise, we should be able to get to this in our Roadmap Priority 2 (next quarter). |
Beta Was this translation helpful? Give feedback.
-
Confirm it, I also encounter this error when uploading csv file via local api. |
Beta Was this translation helpful? Give feedback.
-
Try reading the file first, something like this: import fs from "fs";
const tmpFilePath = 'filePathHere'
const fileBuffer = fs.readFileSync(tmpFilePath);
const geojson = await payload.create({
collection: 'geofiles',
file: {
data: fileBuffer,
mimetype: 'application/geo+json',
name: filename,
size: fileBuffer.byteLength
},
data: {}
});
return geojson.id; |
Beta Was this translation helpful? Give feedback.
-
Bug Report
Calling this:
results in the following error:
I'm using Payload 1.6.6.
Possible cause
I believe the problem lies in the the following code
const mimetype = fromFile(filePath);
(link) which ultimately in the file-type package does thisnew FileTypeParser().parse(tokenizer);
.FileTypeParser.parse()
(link) does not support (geo)JSON.The
file-type
states This package is for detecting binary-based file formats, not text-based formats like .txt, .csv, .svg, etc., does this mean that the payload upload system also only supports binary-based file formats?Beta Was this translation helpful? Give feedback.
All reactions