Android + https 实现 文件上传

package com.example.wbdream.zigvine;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.example.wbdream.zigvine.friends.FriendsData;
import com.example.wbdream.zigvine.friends.FriendsRecyclerAdapter;
import com.example.wbdream.zigvine.https.UpLoadFile;
import com.leon.lfilepickerlibrary.LFilePicker;
import com.leon.lfilepickerlibrary.utils.Constant;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

public class FriendsList extends Fragment {
    private List<JSONObject> mData = null;
    private FriendsData sc = null;
    private SQLiteDatabase db = null;
    private FriendsRecyclerAdapter friendsRecyclerAdapter = null;
    private static final int FILE_CODE = 0;
    private static final String TAG = "FriendsList";
    private String upLoadPath = null;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        Log.e(TAG, "onCreateView: -----finish????-------" );
        setHasOptionsMenu(true);
        final View view = inflater.inflate(R.layout.friends_list,container,false);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        flushData();
        Log.e(TAG, "onActivityCreated: +++++===================" );

//        initData();
//        RecyclerView friends_recycler = getActivity().findViewById(R.id.friends_recycler);
//        LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
//        friends_recycler.setLayoutManager(layoutManager);
//        friendsRecyclerAdapter = new FriendsRecyclerAdapter(getContext(),mData);
//        Log.e(TAG, "onActivityCreated: ====================="+friendsRecyclerAdapter.hashCode() );
//        friendsRecyclerAdapter.setOnItemClickListener(new FriendsRecyclerAdapter.OnItemClickListener() {
//            @Override
//            public void onClick(int position) {
//                Toast.makeText(getContext(),"点击事件"+position,Toast.LENGTH_SHORT).show();
//
//                //初始化某人聊天数据
//                int uid;
//                try {
//                    uid = mData.get(position).getInt("uid");
////                    Cursor cursor = db.rawQuery("select * from CHATRECORD where friends_id = "+ uid,null);
//                    Intent intent = new Intent(getContext(),ChatActivity.class);
//                    intent.putExtra("uid",uid);
//                    startActivity(intent);
//
//                } catch (JSONException e) {
//                    e.printStackTrace();
//                }
//
//            }
//        });
//        friends_recycler.addItemDecoration(new DividerItemDecoration(getContext(),DividerItemDecoration.VERTICAL));
//        friends_recycler.setAdapter(friendsRecyclerAdapter);
//
//        //删除数据库
////        getContext().deleteDatabase("friend1.db");
//
//        //删除表内容
////        db.execSQL("delete from friends");
//        //插入数据
//        ContentValues values = new ContentValues();
//
////        for ( int i=1;i<3;i++) {
////            Log.e(TAG, "onActivityCreated: ______" + "张三" + i);
////            values.put("friends_name","李四"+i);
////            db.insert("FRIENDS", null,values );
////            values.clear();
////        }
//
//        Toast.makeText(getContext(),"初始化数据库",Toast.LENGTH_SHORT).show();
//        Cursor cursor = db.rawQuery("select friends_name,friendId from FRIENDS",null);
//        if (cursor.moveToFirst()){
//            do {
//                String name = cursor.getString(cursor.getColumnIndex("friends_name"));
//                Log.e(TAG, "onActivityCreated: *******"+name +"----"+cursor.getInt(cursor.getColumnIndex("friendId")));
//            }while(cursor.moveToNext());
//
//        }
//        cursor.close();

    }
    //添加menu
    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        inflater.inflate(R.menu.friend_list_menu,menu);
    }
        //menu点击事件

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case R.id.add_friend:
                //跳转页面
                Toast.makeText(getContext(),"add friend",Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(getContext(),AddFriendActivity.class);
                startActivity(intent);

                break;
        }
        return true;
    }

    public void initData() {
        //创建数据库
        sc = new FriendsData(getContext(),"friend.db",null,4);
        db = sc.getWritableDatabase();
        mData = new ArrayList();
        Cursor cursor = db.rawQuery("select * from FRIENDS",null);
        if (cursor.moveToFirst()){
            do {
                JSONObject json=new JSONObject();
                try {
//                    Log.e(TAG, "initData: _________" +cursor.getString(cursor.getColumnIndex("friends_name")));
                    json.put("user_name",cursor.getString(cursor.getColumnIndex("friends_name")));
                    json.put("message","你好呀!");
                    json.put("imageView","");
                    json.put("uid",cursor.getInt(cursor.getColumnIndex("friendId")));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                mData.add(json);
//                Log.e(TAG, "initData: ++++"+mData.size() );
            }while(cursor.moveToNext());

        }
        cursor.close();

    }

    @Override
    public void onResume() {
        Log.e(TAG, "onResume: --------resume------"+friendsRecyclerAdapter.hashCode() );
        Log.e(TAG, "onResume: ==========="+mData.size() );

        flushData();
        super.onResume();
    }

    //刷新数据
    public void flushData(){
        initData();
        RecyclerView friends_recycler = getActivity().findViewById(R.id.friends_recycler);
        LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
        friends_recycler.setLayoutManager(layoutManager);
        friendsRecyclerAdapter = new FriendsRecyclerAdapter(getContext(),mData);
        Log.e(TAG, "onActivityCreated: ====================="+friendsRecyclerAdapter.hashCode() );
        friendsRecyclerAdapter.setOnItemClickListener(new FriendsRecyclerAdapter.OnItemClickListener() {
            int uid;
            @Override
            public void onClick(int position) {
                Toast.makeText(getContext(),"点击事件"+position,Toast.LENGTH_SHORT).show();
                Log.e(TAG, "onClick: ----点击事件----" );
                //初始化某人聊天数据

                try {
                    uid = mData.get(position).getInt("uid");
//                    Cursor cursor = db.rawQuery("select * from CHATRECORD where friends_id = "+ uid,null);
                    Intent intent = new Intent(getContext(),ChatActivity.class);
                    intent.putExtra("uid",uid);
//                    startActivity(intent);
                    Log.e(TAG, "onClick: ----https--" );
                    @SuppressLint("HandlerLeak") final Handler handler = new Handler(){
                        @Override
                        public void handleMessage(Message msg) {
                            super.handleMessage(msg);
                            switch (msg.what){
                                case 111:
                                    Toast.makeText(getContext(),"jjjj"+msg.obj,Toast.LENGTH_SHORT).show();
                                    break;
                            }
                        }
                    };
                    //文件传输
                    String sdpath;
//                    sdpath = "/mnt/";
//                    sdpath = getContext().getFilesDir();
                    Log.e(TAG, "onClick: ----————"+getContext().getFilesDir() );
                    Log.e(TAG, "onClick: ----————"+Environment.getExternalStorageDirectory() );
                    File file = new File(getContext().getFilesDir(),"a2.txt");
                    Log.e(TAG, "onClick: cahgnjan ==========="+!file.exists()+"     "+getContext().getFilesDir() +getContext().getExternalCacheDir() );
                    try {
                        File fp=getContext().getFilesDir();
                        if (!fp.exists()){
                            fp.mkdirs();
                            Log.e(TAG, "onClick: --------创建文件夹" );
                        }
                        getContext().getFilesDir().mkdirs();
                        if (!file.exists()){
                            Log.e(TAG, "onClick: ———创建不成吗—————" );
                            file.createNewFile();
                            System.out.print("jsdhj");
                            Log.e(TAG, "onClick: --------创建了吗" );
                        }
                        FileInputStream inputStream = new FileInputStream(file);
                        inputStream.close();
                        FileOutputStream outputStream = new FileOutputStream(file);
                        outputStream.write("hello".getBytes());
                        outputStream.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                    new LFilePicker().withSupportFragment(FriendsList.this)
                            .withRequestCode(Constant.ICON_STYLE_BLUE)
                            .withTitle("文件管理器")
//                            .withStartPath("/storage/emulated/0/Download")//指定初始显示路径
                            .withStartPath(getContext().getFilesDir().toString())//指定初始显示路径
                            .withNotFoundBooks("至少选择一个文件")
                            .start();
//###############注意这里是  GET   请求   ##########
                    /////////////////
//                    new Thread(new Runnable() {
//
//                        @Override
//                        public void run() {
//                            getHttps();
//                        }
//                        public void getHttps(){
//                            Log.e(TAG, "getHttps:-------执行了吗------ https://192.168.1.34:8000/index/" );
//                            String https = "https://192.168.1.34:8000/index/";
//                            try {
//                                SSLContext sc = SSLContext.getInstance("TLS");
//                                sc.init(null,new TrustManager[]{new MyTrustManager()},new SecureRandom());
//                                HttpsURLConnection.setDefaultSSLSocketFactory((sc.getSocketFactory()));
//                                HttpsURLConnection.setDefaultHostnameVerifier(new MyHostnameVerifier());
//                                HttpsURLConnection conn = (HttpsURLConnection)new URL(https).openConnection();
//                                conn.setDoOutput(true);
//                                conn.setDoInput(true);
//                                Log.e(TAG, "getHttps: ++++++结果111+++++" );
//
//                                conn.connect();
//                                Log.e(TAG, "getHttps: ++++++结果2222+++++" );
//                                BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
//                                StringBuffer sb = new StringBuffer();
//                                String line;
//                                while ((line = br.readLine())!=null){
//                                    sb.append(line);
//                                }
//                                Log.e(TAG, "getHttps: ++++++结果+++++"+sb.toString() );
//                                Message msg = new Message();
//                                msg.what=111;
//                                msg.obj=sb.toString();
//                                handler.sendMessage(msg);
//                            } catch (NoSuchAlgorithmException e) {
//                                e.printStackTrace();
//                            } catch (KeyManagementException e) {
//                                e.printStackTrace();
//                            } catch (MalformedURLException e) {
//                                e.printStackTrace();
//                            } catch (IOException e) {
//                                e.printStackTrace();
//                            }
//                        }
//                        class MyHostnameVerifier implements HostnameVerifier{
//                            @Override
//                            public boolean verify(String hostname, SSLSession session) {
//                                // TODO Auto-generated method stub
//                                return true;
//                            }
//
//                        }
//
//                        class MyTrustManager implements X509TrustManager{
//                            @Override
//                            public void checkClientTrusted(X509Certificate[] chain, String authType)
//                                    throws CertificateException {
//                                // TODO Auto-generated method stub
//                            }
//                            @Override
//                            public void checkServerTrusted(X509Certificate[] chain, String authType)
//
//                                    throws CertificateException {
//                                // TODO Auto-generated method stub
//                            }
//                            @Override
//                            public X509Certificate[] getAcceptedIssuers() {
//                                // TODO Auto-generated method stub
//                                return null;
//                            }
//
//                        }
//
//                    }).start();

                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }
            //清空聊天记录
            @Override
            public void clearRecord(int position) {
                try {
                    uid = mData.get(position).getInt("uid");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                db.execSQL("delete from chatrecord where friends_id = "+ uid+";");
                Cursor cursor2 =db.rawQuery("select * from CHATRECORD ;",null);

                Log.e(TAG, "clearRecord: " +cursor2.moveToFirst() + db.equals(null));
                if (cursor2.moveToFirst()){
                    do {
                        Log.e(TAG, "clearRecord: 00-----"+cursor2.getString(cursor2.getColumnIndex("content")) );
                    }while (cursor2.moveToNext());
                }
                Log.e(TAG, "clearRecord: 8888888888" +"delete from CHATRECORD where friends_id ="+ uid);
            }

//            @Override
//            public void onLongClick(int position) {
//                Toast.makeText(getContext(),"长按事件",Toast.LENGTH_SHORT).show();
//                Log.e(TAG, "onLongClick: ___***长按事件**___" );
////                AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
////                builder.setTitle("hahahha");
////                builder.show();
//
//                //长按功能键
//            }
        });
        friends_recycler.addItemDecoration(new DividerItemDecoration(getContext(),DividerItemDecoration.VERTICAL));
        friends_recycler.setAdapter(friendsRecyclerAdapter);

        //删除数据库
//        getContext().deleteDatabase("friend1.db");

        //删除表内容
//        db.execSQL("delete from CHATRECORD");
        //插入数据
        ContentValues values = new ContentValues();

//        for ( int i=1;i<3;i++) {
//            Log.e(TAG, "onActivityCreated: ______" + "张三" + i);
//            values.put("friends_name","李四"+i);
//            db.insert("FRIENDS", null,values );
//            values.clear();
//        }

        Toast.makeText(getContext(),"初始化数据库",Toast.LENGTH_SHORT).show();
        Cursor cursor = db.rawQuery("select friends_name,friendId from FRIENDS",null);
        if (cursor.moveToFirst()){
            do {
                String name = cursor.getString(cursor.getColumnIndex("friends_name"));
                Log.e(TAG, "onActivityCreated: *******"+name +"----"+cursor.getInt(cursor.getColumnIndex("friendId")));
            }while(cursor.moveToNext());

        }
        cursor.close();

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == Activity.RESULT_OK) {
//            List<String> list = data.getStringArrayListExtra("paths");
//            String path = data.getStringExtra("path");
//            String param = data.getStringExtra("param");
            List<String> list = null;
            list = data.getStringArrayListExtra(Constant.RESULT_INFO);
            //选中文件
            if (list.size()>0){
                for (String string: list) {
                    Log.e(TAG, "onActivityResult: *************"+string );
                    File file =new File(string);
                    upLoadPath = string;

                    //https请求
                    new Thread(new Runnable() {
                        @Override
                        public void run() {            //################  这里是   认证所有证书    trustAllCerts信任所有的证书###################                 handleSSLHandshake();
            //################  https   POST  请求 #############
                            httpPost("https://192.168.1.32:8000/index/up","/data/user/0/com.example.wbdream.zigvine/files/a2.txt","a2.txt");
//                            httpPost("https://192.168.1.32:8000/index/up",string,file.getName());

                        }
                    }).start();

                    try {
                        FileReader fr=new FileReader(file);
                        byte[] bytes=new byte[1024];
                        BufferedReader br = new BufferedReader(fr);
                        String s="";
                        while ((s=br.readLine())!=null){
                            Log.e(TAG, "onActivityResult: =============="+s );
                        }
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                }

            }

        }

    }
    /**
     * 往服务器上上传文本  比如log日志
     * @param urlstr        请求的url
     * @param uploadFile    log日志的路径
     *                                    /mnt/shell/emulated/0/LOG/LOG.log
     * @param newName        log日志的名字 LOG.log
     * @return
     */
    public static void httpPost(String urlstr,String uploadFile,String newName) {
        Log.e(TAG,"urlstr="+urlstr+";uploadFile="+uploadFile+";newName="+newName );
        String end = "\r\n";
        String twoHyphens = "--";
        String boundary = "*****";//边界标识
        int TIME_OUT = 10*1000;   //超时时间
        HttpsURLConnection con = null;
        DataOutputStream ds = null;
        InputStream is = null;
        try {
            URL url = new URL(urlstr);
            con = (HttpsURLConnection) url.openConnection();
            Log.e(TAG, "httpPost: 1111111111" );
            con.setReadTimeout(TIME_OUT);
            con.setConnectTimeout(TIME_OUT);
            /* 允许Input、Output,不使用Cache */
            con.setDoInput(true);
            con.setDoOutput(true);
            con.setUseCaches(false);

            // 设置http连接属性
            con.setRequestMethod("POST");//请求方式
            con.setRequestProperty("Connection", "Keep-Alive");//在一次TCP连接中可以持续发送多份数据而不会断开连接
            con.setRequestProperty("Charset", "UTF-8");//设置编码
            con.setRequestProperty("Content-Type",
                    "multipart/form-data;boundary=" + boundary);//multipart/form-data能上传文件的编码格式
            Log.e(TAG, "httpPost: ------------" );
            ds = new DataOutputStream(con.getOutputStream());
            Log.e(TAG, "httpPost: 2222222222" );
            ds.writeBytes(twoHyphens + boundary + end);
            ds.writeBytes("Content-Disposition: form-data; "
                    + "name=\"stblog\";filename=\"" + newName + "\"" + end);
            ds.writeBytes(end);

            // 取得文件的FileInputStream
            FileInputStream fStream = new FileInputStream(uploadFile);
            Log.e(TAG, "httpPost: 333333333333" );
            /* 设置每次写入1024bytes */
            int bufferSize = 1024;
            byte[] buffer = new byte[bufferSize];
            int length = -1;
            /* 从文件读取数据至缓冲区 */
            while ((length = fStream.read(buffer)) != -1) {
                /* 将资料写入DataOutputStream中 */
                ds.write(buffer, 0, length);
            }
            ds.writeBytes(end);
            ds.writeBytes(twoHyphens + boundary + twoHyphens + end);//结束

            fStream.close();
            ds.flush();
            /* 取得Response内容 */
            is = con.getInputStream();
            int ch;
            StringBuffer b = new StringBuffer();
            while ((ch = is.read()) != -1) {
                b.append((char) ch);
            }
            /* 将Response显示于Dialog */
            Log.e(TAG, "httpPost: ------上传成功-----");
        } catch (Exception e) {
            e.printStackTrace();
            Log.e(TAG, "httpPost: ======----"+e );
            Log.e(TAG, "httpPost: --------上传失败----" );
        }finally {
            /* 关闭DataOutputStream */
            if(ds!=null){
                try {
                    ds.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (con != null) {
                con.disconnect();
            }
        }
    }
    public static void handleSSLHandshake() {
        try {
            TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
                public X509Certificate[] getAcceptedIssuers() {
                    return new X509Certificate[0];
                }

                @Override
                public void checkClientTrusted(X509Certificate[] certs, String authType) {
                }

                @Override
                public void checkServerTrusted(X509Certificate[] certs, String authType) {
                }
            }};

            SSLContext sc = SSLContext.getInstance("TLS");
            // trustAllCerts信任所有的证书
            sc.init(null, trustAllCerts, new SecureRandom());
            HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
            HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
                @Override
                public boolean verify(String hostname, SSLSession session) {
                    return true;
                }
            });
        } catch (Exception ignored) {
        }
}
}

 

原文地址:https://www.cnblogs.com/wbdream/p/9993876.html

时间: 2024-11-09 02:02:22

Android + https 实现 文件上传的相关文章

Android WebView 支持 文件上传(Html File Upload)

背景:有个html页面,用html里面自带的<input type =file/>上传文件(图片,word,Excel等)浏览器直接打开可以上传,套壳在Android app里面,点击文件上传没反应,修改Android代码,可以实现相应功能,亲测有效. 1.在oncreate 方法上面 加入以下代码: 1 private static final int REQUEST_STORAGE = 1; 2 private static final int REQUEST_LOCATION = 2;

Android客户端多文件上传

在web开发中,多文件上传时是非常方便的,直接使用Http协议提交数据即可.格式如下: <FORM METHOD=POST ACTION="http://192.168.1.101:8083/upload/servlet/UploadServlet" enctype="multipart/form-data"> <INPUT TYPE="text" NAME="name"> <INPUT TYPE

android Volley 实现文件上传功能

Volley不解释了吧, android 官方的一个网络请求库. 源代码的地址在: [email protected]:com314159/VolleyMultiPartRequest.git 是根据 https://github.com/smanikandan14/Volley-demo 这位大神修改而来的, 但是那位大神的代码有bug, 上传文件不成功. 注: 我的demo里面还集成了okhttp, 不需要的同学不用理这个类即可 实现方法: 1.添加三个jar包, httpcore-4.3.

Android Http POST文件上传之-----RFC1867协议

RFC1867协议介绍 RFC1867协议主要是在HTTP协议的基础上为INPUT标签添加了file属性.同一时候限定了Form的method必须为POST,ENCTYPE必须为multipart/form-data. 其他属性标签, <INPUT TYPE=file>标记能够有一个VALUE属性来指定默认的文件名 ,能够用"SIZE=宽,高"来指定SIZE属性 . multipart/form-data multipart/form-data的媒体内容遵从RFC 1521

Android开发之网络请求通信专题(二):基于HttpClient的文件上传下载

上一篇专题Android开发之网络请求通信专题(一):基于HttpURLConnection的请求通信我们讲解了如何使用httpurlconnection来实现基本的文本数据传输.一般在实际开发中我们可以用于传输xml或者json格式的数据.今天我们来讲解另外一种http网络请求的方式:httpclient,并实现文件的上传和下载. 在这里插个题外话,其实这些网络请求有很多第三方jar包可以使用,这些包都封装得很好了.如果只是想使用,我们就直接拿别人得jar包来用就好.博主这里推荐一个叫xuti

Android OkHttp文件上传与下载的进度监听扩展

相信大家对OkHttp也是相当的熟悉了,毕竟是Square的东西,对于其种种优点,这里也不再叙说.优秀是优秀,但是毕竟优秀的东西给我们封装了太多,那么问题来了,我们使用OkHttp作为我们的网络层,简单地进行GET/POST请求是毫无问题.近日看了产品的设计稿,毛估估会有文件的上传与下载的需求,如果使用OkHttp作为网络层进行封装,你会惊讶的发现,简直封装的太"完美"了.如果现在有这么一个需求,要求对文件进行上传或下载,但是在上传或者下载前,你需要给用户一个友好的提示,在上传或者下载

在Android浏览器中通过WebView调用相机拍照/选择文件 上传到服务器

最近做的一个项目中,有这样一个要求,在浏览器中调用系统的拍照功能或者选择文件,然后将文件上传到服务器,类似修改头像.        简单而言,就是在一个html页面中有这样一段代码 <input class="filePrew" type="file" capture="camera" accept="image/*" name="image"> 刚开始的时候,没有感觉很难的,因为在UC浏览器.

android+spring boot 选择,上传,下载文件

1 概述 前端android,上传与下载文件,使用OkHttp处理请求,后端使用spring boot+MVC,处理android发送来的上传与下载请求.这个其实不难,就是特别多奇奇怪怪的坑,因此,希望看到的,不要像笔者这样踩的那么痛苦了... 2 环境 win10 Spring Boot 2.2.2 RELEASE IDEA 2019.3.1 Android Studio 3.6RC1 Tomcat 9.0.30 3 android 3.1 准备工作 3.1.1 新建工程 这次用一个全新的例子

android批量文件上传(android批量图片上传)

项目中多处用到文件批量上传功能,今天正好解决了此问题,在此写出来,以便日后借鉴. 首先,以下架构下的批量文件上传可能会失败或者不会成功: 1.android客户端+springMVC服务端:服务端采用org.springframework.web.multipart.MultipartHttpServletRequest作为批量上传接收类,这种搭配下的批量文件上传会失败,最终服务端只会接受到一个文件,即只会接受到第一个文件.可能因为MultipartHttpServletRequest对serv