Uploading an image and parameters in one one API call - node.js

i'm having some problems creating an object + uploading an image at the same API call. the server was created by be (Node.js + mongoDB). its a POST that used multer to extract all data (form - data) and all tests using postman seems to be working fine.
i'm using Alamofire in my IOS app
post with content type
upload and multi form data
my server code

Related

Getting PayloadTooLargeError and Cors error simultaneously while sending a large file data through post request from client to server

I am working on a project which has an upload file feature. The text data from this file is to be send to the backend Node js server through axios post request and then uploaded to the database.
While using a smaller file (around 4 kb), it is working fine. But when I upload a large sized file (~10000 kb), I am getting two error simultaneously.
CORS error at the client side (React Js).
PayloadTooLargeError at the server side (Node Js).
I tried using the soluyion given in the post: Error: request entity too large, but it is not working.

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

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

How to read form data in the AWS Lambda written in NodeJs?

I'm building an app using ReactJS in the front-end and back-end as AWS API Gateway/AWS Lambda written in NodeJS.
I'm passing the form data of my React app in the attribute called userAttributes like below:
I want to read this data in the backend logic. As per the Cloud Watch logs of Lambda, I'm getting the form data in the Lambda event as:-
body: '------WebKitFormBoundarytTytoOIkcO2\r\n' +
'Content-Disposition: form-data; name="userAttributes"\r\n' +
'\r\n' +
'[object Object]\r\n' +
'------WebKitFormBoundarytTytrEkb0oOIkcO2--\r\n',
isBase64Encoded: false
}
Here [object Object] is my Form data. How can parse and read this form data value? I can read my other query string parameters (event.queryStringParameters.<attributes>) but not sure how to read the form data.
Use https://www.npmjs.com/package/parse-multipart on your lambda and you can parse the data...
But first
Set the media type in you api gateway as multipart/form-data
When you added your lambda to the api gateway method please be sure
if you check "proxy" because you need that to manage the data from the frontend as multipar/form-data

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/

How to : Read file from API (node) in my React app?

I work on an webapp which use REACT JS (with NODE, port 3000) and an API (with NODE JS, port 3100).
All requests made by client passing throught my API.
In this app, client could be able to listen mp3s downloaded and stored into my API. I made different schemas but I don't know which one can work.
SCHEMA 1.
REACT send parameters to API
API download the file and store it on a temporary directory
API send the URL (like : http://localhost:3100/sound/exemple.mp3) to REACT
REACT use that URL in 'src' of the AudioPlayer
Temporary files are delete with a CRON setting up on API server
I tried that solution but I have an error when I want to play the sound
(error: Can't GET /URL)
SCHEMA 2.
REACT send parameters to API
API download the file and store it on a temporary directory
REACT download the file from API and store it into public directory (by using express static)
REACT use that URL in 'src' of the AudioPlayer
Delete the file twice (API and REACT)
Another solution is to download the file directly from my source on REACT. But I need to hide the URL of the source (that why I pass throught my API).
Maybe there are others solutions ?

Resources