Fix encoding binary files like PDFs for sync from Desktop client

Use readFileSync, Buffer to pass appropriately formatted binary data
This commit is contained in:
sabaimran 2023-10-17 13:05:50 -07:00 committed by Debanjum Singh Solanky
parent 2646c8554d
commit ba60c869c9

View file

@ -135,9 +135,10 @@ function pushDataToKhoj (regenerate = false) {
} }
try { try {
encoding = binaryFileTypes.includes(file.split('.').pop()) ? "binary" : "utf8"; let encoding = binaryFileTypes.includes(file.split('.').pop()) ? "binary" : "utf8";
mimeType = filenameToMimeType(file) + (encoding === "utf8" ? "; charset=UTF-8" : ""); let mimeType = filenameToMimeType(file) + (encoding === "utf8" ? "; charset=UTF-8" : "");
fileObj = new Blob([fs.createReadStream(file, encoding)], { type: mimeType }); let fileContent = Buffer.from(fs.readFileSync(file, { encoding: encoding }), encoding);
let fileObj = new Blob([fileContent], { type: mimeType });
formData.append('files', fileObj, file); formData.append('files', fileObj, file);
state[file] = { state[file] = {
success: true, success: true,