上传/下载图片问题android + PHP + Base64

时间:2014-05-22 03:25:18

标签: php android json bitmap base64

你好,我在上传到服务器的imageButton上显示图像时出现问题。我无法弄清楚我的错误是什么!

这是一个简短的想法,我在上传时正在做什么: 位图图像 - > Base64编码为字符串 - >将字符串上传到服务器 - >将字符串写入文件

下载时我正在做的一个简短的想法: 从文件中读取字符串 - >放入JSON - >在Android中收到 - > Base64解码到字节数组 - >将字节数组解码为位图 - >发布到ImageButton

java代码:

            //Storing image string
            if(scaledBitmap == null){
               bitMapPartyPicture = ((BitmapDrawable)partyPicture.getDrawable()).getBitmap();
            }else{
               bitMapPartyPicture = scaledBitmap;
            }
            String imageString = jsonParser.encodeImage(bitMapPartyPicture);

//Encoding the Image
public String encodeImage(Bitmap image){
    Bitmap bitmap = image;
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
    byte [] byte_arr = stream.toByteArray();
    Log.d("Image Base64",stream.toString());
    String image_str = Base64.encodeToString(byte_arr, Base64.DEFAULT);
    return image_str;
}

public JSONObject makeHttpRequest(String url, String method,List<NameValuePair> params) {
//Upload Image
            try{
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost("http://whatever.com/addProfilePic.php");
                httppost.setEntity(new UrlEncodedFormEntity(params));
                HttpResponse response = httpclient.execute(httppost);
                HttpEntity httpEntity = response.getEntity();
                is = httpEntity.getContent();
                is.reset();
                is.close();
            }catch(Exception e){

                  System.out.println("Error in http connection "+e.toString());
            }
        //Dealing with JSON Object
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    is, "utf-8"), 8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            is.close();
            json = sb.toString();
        } catch (Exception e) {
            Log.e("Buffer Error", "Error converting result " + e.toString());
        }

        // try parse the string to a JSON object
        try {
            Log.d("JSON Object", json);
            jObj = new JSONObject(json);
        } catch (JSONException e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }

        // return JSON String
        return jObj;
}



//Download Image
public byte[] downloadImage(String url,List<NameValuePair> imgName) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    byte[] ImageBytes = new byte[1024];
    String ImageString = null;
    byte[] DecodedImage = new byte[1024];
    try {
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);
        httpPost.setEntity(new UrlEncodedFormEntity(imgName));
        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        is = httpEntity.getContent();

        BufferedReader reader = new BufferedReader(new InputStreamReader(is, "utf-8"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        int LinesValue = 0;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
            LinesValue++;
        }

        json = sb.toString();
        Log.d("Lines",Integer.toString(LinesValue));
        Log.d("JSON Object", json);
        jObj = new JSONObject(json);
        ImageString = jObj.getString("Image_Decoded");
        ImageBytes = ImageString.getBytes(Charset.forName("UTF-8"));
        is.close();

    }
    catch(IOException t) {
        t.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    DecodedImage = Base64.decode(ImageString ,Base64.DEFAULT);

    return DecodedImage;
}

PHP上传方:

$image = $_POST['image'];// name of uploaded image
    $user  = $_POST['user'];
    $image_name = $_POST['imageName'];
    $file = null;
    $filePath = "photos/" . $user;


    $homeDir = "/home/a1400606/public_html/";
    if (!file_exists($homeDir.$filePath)) {
        mkdir($filePath, 0777);
    }
    if($image_name == 'partyPicture'){
        $file = fopen('partyPicture', 'w');
        fwrite($file, $image);
        fclose($file);

    }else if ($image_name == 'profilePicture'){
        $file = fopen('profilePicture', 'w');
        fwrite($file, $image);
        fclose($file);

    }else{
        $response["Error:"] = "Error";
    }

    if(rename(addslashes("$homeDir"."partyPicture"),addslashes( "$homeDir$filePath"."/partyPicture"))){
        $response["File Moved:"] = "Yes";
    }else {
        $response["File Moved:"] = "No";
    }

PHP下载方:

$image = "partyPicture";// name of uploaded image
    $user  = "xxxx";
    $filePath = "photos/" . $user."/";
    $homeDir = "/home/a1400606/public_html/";
    if (!file_exists(addslashes($homeDir.$filePath.$image))) {
        $response["Found File"] = "File doesn't exist";
    }else{
        $response["Found File"] = "File exist in directory";
        $imgstr=fread(fopen($homeDir.$filePath.$image,"r"),filesize($homeDir.$filePath.$image));
        $response["Image_Decoded"] = $imgstr;
    }
    echo json_encode($response);

将图像发布到ImageButton:

        byte[] bytesArray = new byte[1024];
        bytesArray = json.downloadImage(DOWNLOAD_IMAGE_URL, params);
        ImageBitmap = BitmapFactory.decodeByteArray(bytesArray, 0,bytesArray.length);
        if(ImageBitmap == null){
            InputStream is= new ByteArrayInputStream(bytesArray);
            ImageBitmap = BitmapFactory.decodeStream(is);
        }
        CreateImageBitmap = Bitmap.createBitmap(ImageBitmap);

catLog for Uploading:

05-22 00:29:43.874: D/Image Base64(7530): ??????JFIF????????????????C??????C????p0"??????????????????????????   
05-22 00:29:43.874: D/Image Base64(7530): ???????????}??!1AQa"q2???#B??R??$3br? 
05-22 00:29:43.874: D/Image Base64(7530): %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz???????????????????????????????????????????????????????????????????????????????????????????  
05-22 00:29:43.874: D/Image Base64(7530): ?????????w??!1AQaq"2?B????    #3R?br?
05-22 00:29:43.874: D/Image Base64(7530): $4?%?&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz?????????????????????????????????????????????????????????????????????????????????????{<1$?'?r_?O]???`????(,J?_?:?8?R;S????#????????Uy]?lU?FN?s??O??n????  E?gk?:I???S?eI?K?^>???V??~??o??A??$g????s?8?$?k??e?
?>e?~?Ons?g=A#?d?rD??6?1?@'???9??????j?^U?%???I???~?????r?F?????m????_]|?W$????v???E?&?w??zl??=?w3?x?M??QlA$???89??????1o"?Je`????y??}3?=??:??%??0%?c???    ?NFsY?q?D?,RQwI?{?]5???cw}O??$$?2??t???z]??[??hs-?mA??pH??b?C?????W?????$?G.$?????r9??[\Gg<A?v@&??Q?+?$`??n? ?^????A{??o????
05-22 00:29:43.874: D/Image Base64(7530): Ibs?#??>lj????'h?Z2\???}?V???B?9?9???Z&?U??-??x??{???<^??YA?6????\?V??U&ge??r[????'?CWmu??\y?A@?1o??I?B????$??u???^?ti>?:??(??{pS?O?Ms?E????????o?n??NthQ?????K???Z??????>????    ?p?z{??yl??$?X?*\H???t96~?#?-\k2??q}:???G??Sk:?z?x?rI??????r???v?`?y??9??e? 9VvW?m???r??????a9jNrVR?6?g)>f?n???k?4??$?1???g??'$?.?$U=0?;?>???tq?z??n???_S?lc ?????9-?K?$a????9?L~??^?,????IY-uWVM???K=[J???S??r?:i?Y^???????j?Wi$n??BG^XpA?P3?y??'???]NP?
?A??x??????,J?8u%?.?G_|{??&'<?9?????}J?$???kF?ww????%m???S?????????????????\?F=?I;H?=9???5??j??G?n??K7a???y!N}9??????$`?|z?'?p??w?????(?9??8??'????J??Vzn?{O7????B??)k?\???D?????{$./???????c?hk??\c?V?y?=3??3?.>P9????_? ?5v?$I
???`??z?:??I&????(?(%??G???Os????v?Q_?4????u??h?8??f)??px?\~G???kU??FDd??,?8?=3?p20
_??H??;[????}y??O$f?Ymf.???o?N??I???o?
05-22 00:29:43.874: D/Image Base64(7530): ????n|?o????????]??fn?fbF9??[8?? ??]B?]HnH?@i9?^?????????? ?}??t?=??v??*??S?Ts?9?}3?;????T?|??[E??????Wf??g   Mj?IZ???}??}t????Z`e?99??z??????5?!??&p2x???<????$?$
05-22 00:29:43.874: D/Image Base64(7530): ???|?Q???)-???????lc3:?0???N2zq??O??pZ?_??%4?i?/]?iwV?????;?????+?????
05-22 00:29:44.134: D/Address(7530): 567 Beaverbrook Ct
05-22 00:29:44.134: D/PostalCode(7530): E3B
05-22 00:29:44.134: D/City(7530): Fredericton
05-22 00:29:44.134: D/Date Format(7530): 22-5-2014
05-22 00:29:44.134: D/StartDate(7530): 22-5-2014
05-22 00:29:44.134: D/EndDate(7530): 22-5-2014
05-22 00:29:44.134: D/GeoAddress(7530): [Address[addressLines=[0:"567 Beaverbrook Ct",1:"Fredericton, NB E3B",2:"Canada"],feature=567,admin=New Brunswick,sub-admin=null,locality=Fredericton,thoroughfare=Beaverbrook Ct,postalCode=E3B,countryCode=CA,countryName=Canada,hasLatitude=true,latitude=45.9537013,hasLongitude=true,longitude=-66.646423,phone=null,url=null,extras=null]]
05-22 00:29:44.754: I/Choreographer(7530): Skipped 75 frames!  The application may be doing too much work on its main thread.
05-22 00:29:46.614: I/System.out(7530): Error in http connection java.io.IOException
05-22 00:29:48.874: D/JSON Object(7530):        {"File Moved:":"Yes","ImageString":"\/9j\/4AAQSkZJRgABAQAAAQABAAD\/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB\nAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH\/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEB\nAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH\/wAARCAVwAzADASIA\nAhEBAxEB\/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL\/8QAtRAAAgEDAwIEAwUFBAQA\nAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3\nODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWm\np6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6\/8QAHwEA\nAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL\/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSEx\nBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygp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sLWH7TCwYkDI5ORlvm7+o6\/mSWrUh0+61JlR1IjAXaSMZG5sZ59APXqMn

下载Catlog:

05-22 00:30:58.664: D/Lines(7530): 1
05-22 00:30:58.694: D/JSON Object(7530):        {"Found File":"File exist in directory","Image_Decoded":"\/9j\/4AAQSkZJRgABAQAAAQABAAD\/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB\nAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH\/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEB\nAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH\/wAARCAVwAzADASIA\nAhEBAxEB\/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL\/8QAtRAAAgEDAwIEAwUFBAQA\nAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3\nODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWm\np6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6\/8QAHwEA\nAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL\/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSEx\nBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElK\nU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3\nuLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6\/9oADAMBAAIRAxEAPwD8+ns8\nMSQeoyeecl+2T12\/+PEcYJOpDpazKCxKFAPXnl++BjoM9TjPUhs7U9ui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evT8xyMFq8M12xjMzrkMAOrAE4yenHQ\/U\/w8HBanl+P\nnCU0k2nKL13vaXdW1sr\/ADvdpoiliqkrqK\/l6+bSbu\/K1n53u02\/nu\/s5ZQ8jA5wByOdoJxnnocf\nnxng54G8h2yyJjkEAjnsznOCCc\/KD\/jyT75rlnBBA4VuqIcbQBnLg8598+\/Qk5Brxi8SN55XHLBs\nhdo5G5u\/b7vP\/wBevvslqe1jUm3q05tOyeyvp9781bzZ6eEvL2nPvJR5vxv1\/wCDq9d75trO1qN6\njPPAJ+YckdcdO59iOu3JR\/EEwmeFYyQAuCcjOdxPQn0PXqcckgE3lgEhJYfp6Z98DOOn68jMH2eL\nzmURBiCOScEgA4P0749+TjNdc6MpTlJ6Ra0ej15pW05r7c3463sdPsaaVrr7n\/8AI+vTq9Wya21K\nRpA7Lwc4GT\/tYx\/3yMnP8QHUZPoHh3WljcB2A4H1U\/MOOent659SRxkcMUMbSSKFVR6cEksBznjq\nfoQRk4yYrO6SS4eO3wTu4GSMncRkgHnjd055PJIOeGvgYVVLVuVoxfu9OaXdtfjs1q2nfnrUacou\nKdmktk0muae7aWvVa230tzH2r8Mta+3XiQMD5aNGoZeRt3Hoec5xyD149cn9OPhsukTaXHAWCt5a\nMfm5IBfnjnkAdTj5eoLEV+WnwPjC3NqLuMRK\/lfP3J8wAn5h246+o6Hk\/qJ4N0wRWcEtrhomCK0u\nQMKSxxwTySM\/XPOGc18XPJaSqVXDWfPNxT0XNzz6t6bJ\/erO0m+fBYaLc1HV81rdb3kn0s+yt1T6\nx195tdJsLWH7TCwYkDI5ORlvm7+o6\/mSWrUh0+61JlR
05-22 00:30:58.804: I/dalvikvm(7530): Jit: resizing JitTable from 8192 to 16384
05-22 00:30:59.134: D/bytesArray(7530): [B@423fc2e0

2 个答案:

答案 0 :(得分:0)

我认为问题在于将数据存储在文件中。而且你也没有在服务器端提供文件扩展名,所以它创建了垃圾文件。检查它并给.jpg或.png文件名..我希望这会帮助你..

答案 1 :(得分:0)

虽然答复很晚但可能对某人有所帮助..

您正在将图像在android中编码为base64,然后才能上传

但是在将它保存为图像之前,你无法在php端解码它。

<?php
    $image = base64_decode($_POST['image']);// decoding the uploaded image
    $user  = $_POST['user'];
    $image_name = $_POST['imageName'];
    $file = null;
    $filePath = "photos/" . $user;

希望有所帮助......