Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.03 KB | None | 0 0
  1. public void uploadDatabase() {
  2.         AsyncHttpClient client = new AsyncHttpClient();
  3.  
  4.                // .setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
  5.         try {
  6.  
  7.             if (databaseFile.isFile()) {
  8.  
  9.                 byte[] myByteArray = FileUtils.readFileToByteArray(databaseFile); //Files.readAllBytes(videoFile.toPath());
  10.  
  11.                 RequestParams params = new RequestParams();
  12.                 params.put("uploaded_file", new ByteArrayInputStream(myByteArray), "accelerometer.db");
  13.                 //params.put
  14.  
  15.                 params.setForceMultipartEntityContentType(true);
  16.  
  17.                 client.post(POST_URL, params, new AsyncHttpResponseHandler() {
  18.  
  19.                     @Override
  20.                     public void onFinish() {
  21.  
  22.                         Log.d("FINISH",this.getRequestHeaders().toString());
  23.                         Log.d("FINISH",this.getRequestURI().toString());
  24.                         // default log warning is not necessary, because this method is just optional notification
  25.                     }
  26.  
  27.                     @Override
  28.                     public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
  29.  
  30.                         if (statusCode == 200) {
  31.                             Log.d(TAG,"SUCCESS - The database uploaded successfully");
  32.                         }
  33.                     }
  34.  
  35.                     @Override
  36.                     public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
  37.                         //Log.d("LOGGING HEADERS","FAILURE - Something went wrong. Plase try again later.");
  38.  
  39.                         Log.d("NETWORK CONNECTION FAILED","FAILURE - Something went wrong. Please try again later.VINEEL" + error.getCause() +" ");
  40.                     }
  41.                 });
  42.             } else {
  43.             }
  44.  
  45.         } catch (Exception ex) {
  46.             Log.e(TAG,"Exception while uploading video to server - "+ex.getMessage());
  47.             ex.printStackTrace();
  48.         }
  49.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement