1919import java .io .FileInputStream ;
2020import java .net .HttpURLConnection ;
2121import java .net .URL ;
22+ import java .security .cert .X509Certificate ;
23+
24+ import javax .net .ssl .HttpsURLConnection ;
25+ import javax .net .ssl .SSLContext ;
26+ import javax .net .ssl .TrustManager ;
27+ import javax .net .ssl .X509TrustManager ;
2228
2329public class FileUploader extends AsyncTask <String , Void , String > {
2430 private Promise promise ;
@@ -54,9 +60,30 @@ private void sendProgressEvent(float progress) {
5460 @ Override
5561 protected String doInBackground (String ... params ) {
5662 try {
63+
64+ TrustManager [] trustAllCerts = new TrustManager [] {
65+ new X509TrustManager () {
66+ public java .security .cert .X509Certificate [] getAcceptedIssuers ()
67+ {
68+ return null ;
69+ }
70+ public void checkClientTrusted (X509Certificate [] certs , String authType )
71+ {
72+ //
73+ }
74+ public void checkServerTrusted (X509Certificate [] certs , String authType )
75+ {
76+ //
77+ }
78+ }
79+ };
80+ SSLContext sc = SSLContext .getInstance ("TLS" );
81+ sc .init (null , trustAllCerts , new java .security .SecureRandom ());
82+ HttpsURLConnection .setDefaultSSLSocketFactory (sc .getSocketFactory ());
83+
5784 String sourceFileUri = fileUrl ;
5885
59- HttpURLConnection conn = null ;
86+ HttpsURLConnection conn = null ;
6087 DataOutputStream dos = null ;
6188 String lineEnd = "\r \n " ;
6289 String twoHyphens = "--" ;
@@ -74,19 +101,16 @@ protected String doInBackground(String... params) {
74101 FileInputStream fileInputStream = new FileInputStream (
75102 sourceFile );
76103 URL url = new URL (upLoadServerUri );
77- conn = (HttpURLConnection ) url .openConnection ();
78-
104+ conn = (HttpsURLConnection ) url .openConnection ();
79105 ReadableMapKeySetIterator headerIterator = this .options .headers .keySetIterator ();
80106 while (headerIterator .hasNextKey ()) {
81107 String key = headerIterator .nextKey ();
82108 String value = this .options .headers .getString (key );
83109 Log .d (TAG , key +" value: " +value );
84110 conn .setRequestProperty (key , value );
85111 }
86-
87112 conn .setUseCaches (false ); // Don't use a Cached Copy
88113 conn .setRequestMethod (this .options .method );
89- conn .setRequestProperty ("file" , sourceFileUri );
90114 conn .connect ();
91115 dos = new DataOutputStream (conn .getOutputStream ());
92116
@@ -135,7 +159,7 @@ protected String doInBackground(String... params) {
135159 }
136160 else
137161 {
138- Log .d (TAG , serverResponseMessage +" doInBackground: error" +conn .getResponseCode ());
162+ Log .d (TAG , serverResponseMessage +" doInBackground: error " +conn .getResponseCode ());
139163 this .promise .reject ("" );
140164 }
141165
0 commit comments