Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
base64字符串未上载到服务器android中?_Android_Base64_Android Image_Android Gallery - Fatal编程技术网

base64字符串未上载到服务器android中?

base64字符串未上载到服务器android中?,android,base64,android-image,android-gallery,Android,Base64,Android Image,Android Gallery,我需要将图像(从gallery)以base64字符串格式发送到服务器。我得到图像的路径并将其转换为base64字符串。但在服务器上,图像并没有完全显示出来。只有10%的图像显示在服务器端。请任何人帮助我如何将图像转换为base64字符串 代码: 图像大小:460kb试试这个,我希望它能为您工作,并使用httpPost方法发送 公共静态字符串位图字符串(位图bmp){ 和服务器端 Base64 Base64=新的Base64(); saveImage(base64.decode(profilePi

我需要将图像(从gallery)以base64字符串格式发送到服务器。我得到图像的路径并将其转换为base64字符串。但在服务器上,图像并没有完全显示出来。只有10%的图像显示在服务器端。请任何人帮助我如何将图像转换为base64字符串

代码:


图像大小:460kb

试试这个,我希望它能为您工作,并使用httpPost方法发送

公共静态字符串位图字符串(位图bmp){

和服务器端

Base64 Base64=新的Base64();
saveImage(base64.decode(profilePic),“yourName”)


使用httpPost方法发送。@vikas..我不知道服务器端代码(.net服务)。我只是发送代码并在服务器端检查,而没有使用http post发送。我应该使用http post发送吗?@androidandroid使用httpPost客户端b,因为httpGet有限制,所以您不能发送大数据。ex-HttpClient HttpClient=new DefaultHttpClient();HttpPost=new HttpPost(“您的Url”);获取文件路径后,我将其转换为base64string并获取代码。之后,我将代码发送给服务器人员并进行检查……不使用服务
filePath = cursor.getString(columnIndex);    

Bitmap bitmapOrg = BitmapFactory.decodeFile(filePath);
ByteArrayOutputStream bao = new ByteArrayOutputStream();
bitmapOrg.compress(CompressFormat.PNG, 100, bao);
byte [] ba = bao.toByteArray();
ba1 =Base64.encodeToString(ba, Base64.DEFAULT);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
String base64 = Base64.encodeToString(byteArray, Base64.DEFAULT);
return base64;
}  
public void saveImage(byte[] bytes,String name){

    String path="D:/"+name.hashCode()+".png";
 try {
        FileOutputStream f = new FileOutputStream(path);
        f.write(bytes);
        f.close();
    } catch (Exception e) {

    e.printStackTrace();
    }



 }