alexwhitman / node-pushbullet-api

PushBullet API module for Node.js
165 stars 36 forks source link

File uploader was not handling stream object properly alexwhitman/nod… #50

Open davidnewcomb opened 12 months ago

davidnewcomb commented 12 months ago

In pushes.js#70 you have:

formData.append('file', fs.createReadStream(filePath));

I think something has changed here. formData.append(name, x) expects a string here so fs.createReadStream(filePath) is toString()'ed to "[object Object]" and that is what the body of the request is.

There are some differences between native FormData and node-fetchFormData` and I think there might be some confusion here.

I have removed the streaming component part and replaced it with what was on the node-fetch website for handling file uploads using the File object. Now it works and I can see my pictures in the app.

When I was trying to get it to work last time there was also an issue with the file path not being found. I think that was something to do with streams not really knowing where they are from. Anyway, it only worked before if I didn't add a path to the file e.g. '1-jack.jpg' worked but '/path/to/1-jack.jpg' did not work. That appears to be fixed too (with this implementation).

Related to #49