The Android platform implements image transfer to the server and reproduces it in the server folder (client program + server program)

overview

Recently, due to project requirements, it is necessary to implement a function that can upload photos from an Android phone to a server and reproduce them in a folder on the server. The demos written before are all about the transmission of text information, and have not involved the transmission of files and pictures. This time, I just want to know the specific implementation method.
The basic idea of ​​the implementation is to convert the picture into a byte stream first, and then convert it into String type data. transfer afterwards. After transmission to the server, the data is reproduced as pictures on the server, and finally stored in a folder within the server. Because I am also new to the function of image transmission, and what I implemented is the simplest function, so please correct me if there are any mistakes or unprofessional terms.
Due to space limitations, this article will be divided into several articles and modules to achieve the overall function.

Preparation

The client code is written with Android Studio, so it is necessary to configure the development environment of Android Studio; the server-side code is written with NetBeans; after writing, the ".war" file generated by packaging is Tomcat mounted on the server In; therefore, the above development environments need to be configured before development.

client program

The main functions that the client needs to implement include:
1. Call the camera to take pictures/select photos from the album.
The specific code is in this article:
Android realizes calling the mobile phone camera to take pictures and store them as files
2. Convert the obtained photos into byte streams, and further convert them into String-type data (for the next step of transmission).
The specific code is in this article:
Android converts the picture into a byte stream, and further converts it into String type data
3. Transfer the converted data to the server. Here I am using the Volley framework. Although the Volley framework has some unavoidable shortcomings in transferring pictures, since the Volley framework has been used before, and the time is relatively urgent, the Volley framework is used first. If you are interested, you can use other frameworks (OKHttp, HttpClient, etc.).
The specific code is in this article:
Android uses the Volley framework for data transmission

server program

The function to be realized on the server side is: to receive the data from the client, and re-convert the data into a byte stream, and then convert it into a picture in ".jpg" format.
The specific code is in this article:
Java Web program to convert String type data into JPG pictures and store them in folders

postscript

Although the above code realizes the picture transmission and the picture reproduction function on the server side, it is only the most basic function. At the same time, image transmission involves a lot of knowledge, including data type conversion, Http protocol, etc. So if there are any mistakes in this article, please correct me.
————————————————————————————————————————————
Finally, post your own official account: Wechat search for "Chaqian" or scan the picture below, and usually update some programming on it Related articles, welcome to pay attention~
tea move

Supongo que te gusta

Origin blog.csdn.net/weixin_46269688/article/details/111302750
Recomendado
Clasificación