Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void uploadImageFile(DataOutputStream dos, Bitmap image)
- {
- if (image == null)
- return;
- int bytesRead, bytesAvailable, bufferSize;
- byte[] buffer;
- int maxBufferSize = 1024 * 1024;
- try {
- InputStream is;
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- image.compress(Bitmap.CompressFormat.JPEG, 100 /*ignored for PNG*/, bos);
- byte[] bitmapdata = bos.toByteArray();
- InputStream imageFile = new ByteArrayInputStream(bitmapdata);
- is = new BufferedInputStream(imageFile);
- String file_name_key = "report_foto";
- String upload_file_name = "report_foto.jpg";
- dos.writeBytes(twoHyphens + boundary + lineEnd);
- dos.writeBytes("Content-Disposition: form-data; name=\"" + file_name_key + "\";filename=\"" + upload_file_name + "\"" + lineEnd); // uploaded_file_name
- dos.writeBytes(lineEnd);
- bytesAvailable = is.available();
- bufferSize = Math.min(bytesAvailable, maxBufferSize);
- Log.d(("Image length " + bytesAvailable + " - " + maxBufferSize + " = " + bufferSize + ""));
- buffer = new byte[bufferSize];
- bytesRead = is.read(buffer, 0, bufferSize);
- while (bytesRead > 0) {
- dos.write(buffer, 0, bufferSize);
- bytesAvailable = is.available();
- bufferSize = Math.min(bytesAvailable, maxBufferSize);
- bytesRead = is.read(buffer, 0, bufferSize);
- }
- dos.writeBytes(lineEnd);
- is.close();
- } catch (IOException ioe) {
- Log.e("Debug" + " error: " + ioe.getMessage());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement