Previously I created a REST API which was taking a ZIP file and two other parameters as input from the flutter mobile application
var uri = Uri.parse("http://XX.XXX.XX.XX/gatewayapp/userinfo/sendFileToServer/");
var request = http.MultipartRequest('POST', uri);
Map<String, String> headers = {
"Accept": "application/json"
};
//add headers
request.headers.addAll(headers);
request.fields["customerNumber"] = customerNumber;
request.fields['zippassword'] = password;
var file= await http.MultipartFile.fromPath(
'userDetailsFile',
filePath
);
request.files.add(file);
await request.send().then((streamedResponse) async {
....Implemented the business logic on the response which I was getting
}
It was working as per the expectation.
We moved the API from HTTP to HTTPS using Nginx on the AWS server and changed all the GET and POST-call from the mobile application using HTTPClient and HttpClientRequest and it worked as per the expectation.
However, we are not able to do a multipart request using HTTPClient and HttpClientRequest on the API. I tried using httpclient method but no luck. I also tried something which is given on the below link :
Using HTTPClient on Dart lang github
var uri = Uri.parse("https://XX.XXX.XX.XX/gatewayapp/userinfo/sendFileToServer/");
HttpClient client = await CommonController.createHttpClient();
HttpClientRequest request = await client.post( uri.toString() , 443, filePath);
Can anyone please help me move forward in the right direction? Any help would be appreciated! Thanks
Apologies for the answering the question so late.
I was able to send ZIP file using SSL (Self Signed certificate deployed on AWS) using the HTTPClient provided by flutter.
Issue
When we generated certificate using Open SSL and added those certificates in the NGINX configuration to enable SSL. (It was not having root permission.)
We were able to hit the first HTTPS request by adding SSL certificate in the
HTTPClientRequest
as show in below code. But were getting error in the sub sequent HTTP request.We were adding the certificate every time we were making a HTTP request and getting a error of Bad SSL Handshake exception :
Steps to fix the issue
/etc/ssl/
folder of the system as the certificate requires root access.I will add the code sample for adding the certificate using Singleton pattern and making the HTTP calls.