Android uploads files to the server and displays the progress bar

Recently, I was doing the service of uploading files. I simply read the online tutorial. Share the code with practice.

Because most of the Internet have no server code, this can't be done. How can I debug without a server.

OK, code first.

Android upload is relatively simple. It mainly uses the httpurlconnection class, and then adds a progress bar component.

The main process is to inherit asynctask, and then use httpurlconnection to upload files. The code is relatively simple, so I won't explain it one by one. One thing to note is that you need to

Set name as the parameter name of the web request. Since my server sets the file as the file parameter, I can fill in file directly Therefore, we can make corresponding modifications according to the actual situation.

Then go to the server code. The server mainly uses the status 2 framework for requests. Then we need to package.

The method of multi file upload is adopted, and the list set is defined. Then, the action of processing file upload is a test method. This is defined as testupload

There are not many actions to complete here. Now you need to start writing the upload method UploadFile (int index). Since file is defined as multi file upload, and we upload only one file, the parameter here is 0

The above method is to get the files in the cache area into the D: / / uploaddata / file, and then name them in their own format. Here, I use the UUID and file name of the computer to ensure that the files I copy are not repeated. Finally, after the upload is successful, the real address of the file is returned.

OK, I've basically finished the function of uploading files here. Finally, only the configuration action is left.

OK, let's open status XML file

It mainly defines the temporary storage location of uploaded files, and then the size limit. You can configure it according to the actual situation.

Finally, upload a rendering.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>