SHARE
TWEET

Untitled

a guest Apr 24th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   void uploadImageFile(DataOutputStream dos, Bitmap image)
  2.     {
  3.         if (image == null)
  4.             return;
  5.         int bytesRead, bytesAvailable, bufferSize;
  6.         byte[] buffer;
  7.         int maxBufferSize = 1024 * 1024;
  8.         try {
  9.  
  10.             InputStream is;
  11.             ByteArrayOutputStream bos = new ByteArrayOutputStream();
  12.             image.compress(Bitmap.CompressFormat.JPEG, 100 /*ignored for PNG*/, bos);
  13.             byte[] bitmapdata = bos.toByteArray();
  14.  
  15.             InputStream imageFile = new ByteArrayInputStream(bitmapdata);
  16.             is = new BufferedInputStream(imageFile);
  17.  
  18.             String file_name_key = "report_foto";
  19.             String upload_file_name = "report_foto.jpg";
  20.  
  21.             dos.writeBytes(twoHyphens + boundary + lineEnd);
  22.             dos.writeBytes("Content-Disposition: form-data; name=\"" + file_name_key + "\";filename=\"" + upload_file_name + "\"" + lineEnd); // uploaded_file_name
  23.             dos.writeBytes(lineEnd);
  24.             bytesAvailable = is.available();
  25.             bufferSize = Math.min(bytesAvailable, maxBufferSize);
  26.             Log.d(("Image length " + bytesAvailable + " - " + maxBufferSize + " = " + bufferSize + ""));
  27.             buffer = new byte[bufferSize];
  28.             bytesRead = is.read(buffer, 0, bufferSize);
  29.             while (bytesRead > 0) {
  30.                 dos.write(buffer, 0, bufferSize);
  31.                 bytesAvailable = is.available();
  32.                 bufferSize = Math.min(bytesAvailable, maxBufferSize);
  33.                 bytesRead = is.read(buffer, 0, bufferSize);
  34.             }
  35.             dos.writeBytes(lineEnd);
  36.             is.close();
  37.         } catch (IOException ioe) {
  38.             Log.e("Debug" + " error: " + ioe.getMessage());
  39.         }
  40.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top