Guest User

Untitled

a guest
Jan 20th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. FileInputStream fileInputStream = new FileInputStream(selectedFile);
  2. URL url = new URL(SERVER_URL);
  3. connection = (HttpsURLConnection) url.openConnection();
  4. connection.setDoInput(true);//Allow Inputs
  5. connection.setDoOutput(true);//Allow Outputs
  6. connection.setUseCaches(false);//Don't use a cached Copy
  7. connection.setChunkedStreamingMode(1024);
  8. connection.setRequestMethod("POST");
  9. connection.setRequestProperty("Connection", "Keep-Alive");
  10. connection.setRequestProperty("Cache-Control", "no-cache, must-revalidate");
  11. connection.setRequestProperty("Expires", "Sat, 26 Jul 1997 05:00:00 GMT");
  12. connection.setRequestProperty("ENCTYPE", "multipart/form-data");
  13. connection.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
  14. connection.setRequestProperty("uploaded_file",selectedFilePath);
  15.  
  16. InputStream in = connection.getInputStream();
  17. byte data[] = new byte[1024];
  18. int counter = -1;
  19. String jsonstring = "";
  20.  
  21. while( (counter = in.read(data)) != -1){
  22. jsonString += new String(data, 0, counter);
  23. }
  24.  
  25. Log.d("Debug", " JSON String: " + jsonString);
Add Comment
Please, Sign In to add comment