Using KSOAP for file transfer from android applica

2019-09-02 06:06发布

问题:

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



标签: android ksoap