Android上传图片至java服务器

本文介绍了如何从Android客户端将拍照或相册中的图片上传到使用Intellij Idea和Tomcat搭建的Java服务器。详细提供了客户端的权限设置、布局文件和代码,以及服务器端的项目结构、关键代码和运行结果。
摘要由CSDN通过智能技术生成

这几天有做到一个小的案例,手机拍照、相册照片上传到服务器。客户端和服务器的代码都贴出来:

客户端
AndroidManifest.xml添加以下权限

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

客户端的上传图片activity_upload.xml布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="300dp"/>

    <EditText
        android:id="@+id/editText"
        android:layout_width="match_parent"
        android:layout_height="42dp"
        android:layout_margin="16dp"
        android:background="@drawable/edit_text_bg"/>

    <Button
        android:id="@+id/choose_image"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="选择图片"/>

    <Button
        android:id="@+id/upload_image"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="上传图片"/>

</LinearLayout>

UploadActivity.java界面代码

package com.eric.uploadimage;

import android.annotation.SuppressLint;
  • 6
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值