Using KSOAP for file transfer from android application to web service

寵の児 提交于 2020-02-08 06:44:07

问题


I have sent the data from the android application to the webservice which further will transfer it to the browser by using KSOAP. now i am planning to transfer a file from the app to the web service. Is it possible?


回答1:


InputStream is = null;
try{
    is = new BufferedInputStream(new FileInputStream(Environment.getExternalStorageDirectory().getAbsolutePath() +"/Filename"));
}   
catch (FileNotFoundException e1) {
    e1.printStackTrace();
}   

ByteArrayOutputStream bos = new ByteArrayOutputStream();

try {
    while (is.available() > 0) {
        bos.write(is.read());
    }
} 
catch (IOException e1) {
    e1.printStackTrace();
}

byte[] byteArray = bos.toByteArray();               
String base64= Base64.encodeToString(byteArray, Base64.DEFAULT);

1st step: Get the file from the SDcard and assign that file in INPUTSTREAM.

2nd step: Write the file into BYTEARRAYOUTPUTSTREAM

3rd step: Convert that Stream into BYTEARRAY

4th step: Convert Bytearray into BASE64STRING



来源:https://stackoverflow.com/questions/15491518/using-ksoap-for-file-transfer-from-android-application-to-web-service

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!