Android将黑色图像上传到服务器

Android将黑色图像上传到服务器,android,image,upload,Android,Image,Upload,我有这个代码用于将图像上传到服务器。首先,我从gallery中选择一个图像,当我想要上传它时,我将img路径传递给一个异步任务,但在我上传它之后,没有错误,服务器显示一个黑色图像。 我认为这与编码有关 下面的代码是上载映像的my async的一部分: 位图bitmapOrg=BitmapFactory.decodeFileIMG\u路径; ByteArrayOutputStream=新建ByteArrayOutputStream 使用以下功能 将图像的位图和上载图像的url传递给函数 p

我有这个代码用于将图像上传到服务器。首先,我从gallery中选择一个图像,当我想要上传它时,我将img路径传递给一个异步任务,但在我上传它之后,没有错误,服务器显示一个黑色图像。 我认为这与编码有关

下面的代码是上载映像的my async的一部分:

位图bitmapOrg=BitmapFactory.decodeFileIMG\u路径; ByteArrayOutputStream=新建ByteArrayOutputStream


使用以下功能

将图像的位图和上载图像的url传递给函数

    private String uploadSlike(Bitmap bitmapOrg, String url) {
    String sponse = null;
    InputStream is;
    try {

        ByteArrayOutputStream bao = new ByteArrayOutputStream();

        bitmapOrg.compress(Bitmap.CompressFormat.PNG, 90, bao);

        byte[] ba = bao.toByteArray();

        String ba1 = Base64.encodeBytes(ba);

        ArrayList<NameValuePair> nameValuePairs = new

        ArrayList<NameValuePair>();

        nameValuePairs.add(new BasicNameValuePair("imgdata", ba1));

        HttpClient httpclient = new DefaultHttpClient();

        HttpPost httppost = new

        HttpPost(url);

        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        HttpResponse response = httpclient.execute(httppost);

        HttpEntity entity = response.getEntity();

        is = entity.getContent();
        sponse = convertStreamToString(is);
        // String message=convertResponseToString(response);

    } catch (Exception e) {

    }

    return sponse;

}

public static String convertStreamToString(InputStream is) throws Exception {
    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    StringBuilder sb = new StringBuilder();
    String line = null;

    while ((line = reader.readLine()) != null) {
        sb.append(line);
    }

    is.close();

    return sb.toString();
}

仍然得到一个黑色的图像:我正在添加额外的POST参数,你认为这有什么关系吗?可能有一些服务器端脚本错误…因为我已经使用了很多次…图像上传fineu也可以尝试这个更新吗?我遇到了同样的问题
    private String uploadSlike(Bitmap bitmapOrg, String url) {
    String sponse = null;
    InputStream is;
    try {

        ByteArrayOutputStream bao = new ByteArrayOutputStream();

        bitmapOrg.compress(Bitmap.CompressFormat.PNG, 90, bao);

        byte[] ba = bao.toByteArray();

        String ba1 = Base64.encodeBytes(ba);

        ArrayList<NameValuePair> nameValuePairs = new

        ArrayList<NameValuePair>();

        nameValuePairs.add(new BasicNameValuePair("imgdata", ba1));

        HttpClient httpclient = new DefaultHttpClient();

        HttpPost httppost = new

        HttpPost(url);

        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        HttpResponse response = httpclient.execute(httppost);

        HttpEntity entity = response.getEntity();

        is = entity.getContent();
        sponse = convertStreamToString(is);
        // String message=convertResponseToString(response);

    } catch (Exception e) {

    }

    return sponse;

}

public static String convertStreamToString(InputStream is) throws Exception {
    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    StringBuilder sb = new StringBuilder();
    String line = null;

    while ((line = reader.readLine()) != null) {
        sb.append(line);
    }

    is.close();

    return sb.toString();
}