根据Volley请求以多部分发送图像

时间:2018-10-11 14:44:11

标签: android android-volley multipart

我想发送多部分请求,以便可以通过截击将图像发送到服务器。我想与图像列表一起发送另外两个参数,但是我不知道如何在截击请求参数中传递图像列表。我从图库中获取图像并将其路径存储在数组列表中的代码是:

  <head>
    <?php
        error_reporting(E_ALL);
        ini_set('display_errors', 1);
        $page = basename($_SERVER['PHP_SELF']);
        require_once($_SERVER['DOCUMENT_ROOT'] . '/js/functions.php');
    ?>
    <title>
        <#if title??> ${title}
            <#else> CompSci Resources, LLC | The Complete EDGAR and XBRL Filing Platform, and more!
        </#if>
    </title>

    <script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js'></script>
    <script type='text/javascript' src='${base_url}/js/bootstrap-filestyle.min.js'> </script>
    <script type='text/javascript' src='${base_url}/js/bootstrap.min.js'></script>  
    <script type='text/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/jcarousel/0.3.4/jquery.jcarousel.js'></script>
    <script type='text/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/jcarousel/0.3.4/jquery.jcarousel-autoscroll.min.js'></script>
    <script type='text/javascript' src='${base_url}/js/compsci.js'></script>
    <script type='text/javascript' src='${base_url}/js/carousel.js'></script>
    <script type='text/javascript' src='${base_url}/js/readmore.js'></script>

    <link rel='shortcut icon' href='${base_url}/images/littlelogo.png' >
    <link rel='stylesheet' type='text/css' href='${base_url}/css/jcarousel.css' >
    <link rel='stylesheet' type='text/css' href='${base_url}/css/bootstrap.css'>
    <link rel='stylesheet' type='text/css' media='screen, projection' href='${base_url}/css/compsci.css'>

    <style type='text/css'>
        @media screen and (-webkit-min-device-pixel-ratio:0) { 
            h2 { font-weight: normal; }
            .csr-services-popper-left { margin-top:11px; }
        }
    </style>

    <!-- Google Analytics   -->

    <script type='text/javascript'>
        //Google Analytics
                    var _gaq = _gaq || [];
        _gaq.push(['_setAccount', '${google_analytics_number}']);
        _gaq.push(['_trackPageview']);

        (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
        })();
    </script>

    <meta charset="UTF-8">
    <meta name="language" content="en">
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

其中imageFilePaths是一个数组列表。服务器将接收图像,例如court_image [0],court_image [1]等,这取决于我在arraylist中有多少个图像路径。

齐射要求在这里:

List<String> imagePathList = imageFilePaths;
        List<MultipartBody.Part> partMap = new ArrayList<>();
        for (int i = 0; i < imagePathList.size(); i++) {
            Uri fileUri = Uri.parse(imagePathList.get(i));
            RequestBody requestFile = RequestBody.create(
                    MediaType.parse(getMimeTypee(FileUtils.getFile(getContext(), fileUri).getAbsolutePath())),
                    FileUtils.getFile(getContext(), fileUri)
            );

           MultipartBody.Part body = MultipartBody.Part.createFormData("court_image[" + i + "]", FileUtils.getFile(getContext(), fileUri).getName(), requestFile);
           partMap.add(body);
        }

现在这是我对多部分内容的新手,借助它,我能够从图库中获取图像并将其路径存储在ArrayList中,但是我不知道如何在其中传递多部分数据排球要求。请帮助

0 个答案:

没有答案