问题
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