Accept binary file in body of request on a Nest.js server - node.js

I want to access the binary file uploaded data from the browser.
Nest.js server application works fine from postman but application throws a 400 error when the request is made from the Google Chrome/Angular application.
Thoughts on how to make the Nest.js application accept binary file data? Please let me know.
Attachments for reference:
Postman Request
Google Chrome Request

Related

Connection working from React to NodeJS, but request-url is incorrect in Chrome Network

enter image description hereenter image description hereenter image description here
Assalamu ‘Alaykum
my React app is running on localhost:3000
NodeJS server is running on localhost:1000
I'm sending request to server 'localhost:1000' and everything is fine, correct response is coming from server, there is no error in Console, but in Chrome Network request-url is to localhost:3000/.../...
if I sent wrong data to server, it's coming correct error and bad request error in Console
can someone help me,
thanks
It sounds like your React app is making requests to the wrong URL. Based on the information you provided, it appears that your React app is running on localhost:3000 and your Node.js server is running on localhost:1000, but your requests are being sent to localhost:3000.
To fix this issue, you will need to update your React app to send requests to the correct URL, which should be http://localhost:1000/auth/sign/in. This can typically be done by updating the base URL or endpoint for your API requests in your React app.
For example, if you are using the fetch API to make requests in your React app, you can update the base URL for your requests by setting the baseURL property in your fetch options:
fetch('/auth/sign/in', {
baseURL: 'http://localhost:1000',
// Other fetch options
})
Or, if you are using a library such as Axios to make requests in your React app, you can update the base URL for your requests by setting the baseURL property in the Axios configuration:
import axios from 'axios';
axios.defaults.baseURL = 'http://localhost:1000';
After updating the base URL for your API requests, your React app should send requests to the correct URL, http://localhost:1000/auth/sign/in, and you should no longer see requests being sent to localhost:3000 in the Chrome Network tab.
It's worth noting that the exact solution for updating the base URL for your API requests will depend on the specific details of your React app and how you are making requests to your server. If you are having trouble updating the base URL, you may want to consult the documentation for the specific library or API you are using.

multipart/form-data fetch post gives random output and multer can't extract file

I tried to upload an image file to my server. My client is writing with react native and server is node. I use fetch POST and multipart/form-data on the client side, and multer on server side. When I tried to console.log the request, I got a tons of trash information. I followed the example provided online so I have no idea what's going on. Also multer doesn't extract file from request (req.file is undefined). Also I don't really understand if you post local uri instead of base64 data to your server. How does the server know how to retrieve upload the file through local uri.

How to send an email with excel file as attachment in angular-node app

I am working on angular (frontend) and node ( backend). I want to send an email using sendgrid , With excel file as attachment. I followed the app as reference demo app .Instead of downloading the excel, I want the same file to be sent as email attachment.
Note : In the backend I use nodejs, I am not sure how to pass the file with API to node.js, I can send email in nodejs code.
Can someone help me on this?
You can make an http post request in the node api back-end and pass the file. Do post using headers as Multipart form request.
Multipart form request helps you to make the node js api pass the excel sheet generated on the front end.
In your email service add the http service call to the backend. And make the service pass the file in it
Check this link out for more details
https://blog.jscrambler.com/implementing-file-upload-using-node-and-angular/

Express API response directly outputted in browser instead being handled by Nuxt.js

I have an express server that is connected to mongodb. I have a nuxt route for /account under pages directory. I also have a same route in the express server app.use('/account', account) which is handling the requests.
The database model has been set correctly and the response is sent by the server using return res.status(200).json(User) whenever the route is called upon using a get request. I'm also seeing the response being delivered to the browser.
But the problem is the response is being outputted directly in the browser as raw json. Nuxt is not being loaded to handle the response. I haven't setup any $axios data call in the component using asyncdata or fetch yet.
Here's the sample response that i see in the browser
{"email":"sample#example.com","account":"123445667777"}
I'm not sure what the issue is?

Angular with node.js http failure response for unknown url ): 0 unknown error

So let's start with little info in the beginning.
I have nodejs server side app and client app on angular. I send only get requsts to server app just to read data from database. When i started my apps on local machine they were working pretty well. But when i deployed them to server i got such error : (below in screen)
screen with error from angular
So, i added cors support in server app and add Allow Headers. code in nodejs
But it doesn`t help. When i post "GET" request i get my allow headers in response header and my data that i need in body.
screen with response headers in postman
screen with response body in postman
Server - apache. One interesting thing that server app works good with http protocol and when i am using htttps get this errror error with https
But angular works on https.

Resources