I want to upload all images fetched from the SD card of an Android device to a server. The image array converted in JSON looks as follows:
[
"/storage/emulated/0/DCIM/CAMERA_PIC/IMG_20200217214740.jpg",
"/storage/emulated/0/DCIM/CAMERA_PIC/IMG_20200217215427.jpg",
"/storage/emulated/0/DCIM/CAMERA_PIC/IMG_20200217222919.jpg",
"/storage/emulated/0/DCIM/CAMERA_PIC/IMG_20200218102731.jpg"
]
How can I do this in Java?
The brief answer: It depends (on the backend at the server site and your programming language).
Assuming that you are using JAVA, I found e.g. a tutorial on Downloading & Uploading Images.
We use Java class ByteArrayOutputStream, which can be found under java.io package. […]
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, "jpg", baos);
In order to convert the image to byte array, we use
toByteArray()
method ofByteArrayOutputStream
class: […]byte[] bytes = baos.toByteArray();
Tags: androidandroid, exception, image