0

i trying to upload a picture to a server from android through php. But the problem is, that often pictures dont finish the upload.

Here is a example: http://imageshack.us/a/img20/743/2ut6.jpg

I really dont know where the problem is. Here is my Upload Code:

Bitmap bitmap = bildchen;
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 80, stream); 

    byte[] byte_arr = stream.toByteArray();
    String image_str = Base64.encodeBytes(byte_arr);

    Bitmap ThumbImage = ThumbnailUtils.extractThumbnail(bitmap, 150, 150);
    ByteArrayOutputStream streamt = new ByteArrayOutputStream();
    ThumbImage.compress(Bitmap.CompressFormat.JPEG, 80, streamt); 
    byte[] byte_arrt = stream.toByteArray();
    String image_strt = Base64.encodeBytes(byte_arrt);


    ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

    nameValuePairs.add(new BasicNameValuePair("image", image_str));
    nameValuePairs.add(new BasicNameValuePair("thumb", image_strt));
    nameValuePairs.add(new BasicNameValuePair("UploaderID", ...));
    nameValuePairs.add(new BasicNameValuePair("Beschreibung", t_description
            .getText().toString()));

    try {
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(
                "...");
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);
        final String the_string_response = convertResponseToString(response);
        runOnUiThread(new Runnable() {

            @Override
            public void run() {
                // Toast.makeText(TakePhoto.this,"Response " +
                // the_string_response,Toast.LENGTH_LONG).show();
                addNotification(1, "Upload", the_string_response, false);
                try {
                    Thread.sleep(3000);
                } catch (final Exception e) {
                }
                removeNotification(1);
            }
        });
        String answer = the_string_response.replaceAll("\\D+", "");
        return Integer.parseInt(answer);
    } catch (final Exception e) {
        runOnUiThread(new Runnable() {

            @Override
            public void run() {
                Toast.makeText(TakePhoto.this, "ERROR " + e.getMessage(),
                        Toast.LENGTH_LONG).show();
            }
        });
        System.out.println("Error in http connection " + e.toString());
        return 0;
    }

Thanks for helping me.

4

0 回答 0