使用KSOAP从Android应用程序文件传输到Web服务 [英] Using KSOAP for file transfer from android application to web service
本文介绍了使用KSOAP从Android应用程序文件传输到Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经从Android应用程序,进一步将使用KSOAP其传送到浏览器的WebService发送的数据。我现在计划将文件从应用程序转移到Web服务。这可能吗?
解决方案
InputStream为= NULL;
尝试
{
是=新的BufferedInputStream(。新的FileInputStream(Environment.getExternalStorageDirectory()getAbsolutePath()+/文件名));
} 赶上(FileNotFoundException异常E1){
// TODO自动生成catch块
e1.printStackTrace();
}
ByteArrayOutputStream BOS =新ByteArrayOutputStream();
尝试{
而(is.available()大于0){
bos.write(is.read());
}
}
赶上(IOException异常E1){
// TODO自动生成catch块
e1.printStackTrace();
} 字节[]的字节数组= bos.toByteArray();
字符串的base64 = Base64.en codeToString(字节数组,Base64.DEFAULT);
第1步:从SD卡的文件,并指定在该文件中的的InputStream
。第二步:将文件写入 BYTEARRAYOUTPUTSTREAM
第三步:将其转换成流的字节组
第四步:将ByteArray传递到 BASE64STRING
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?
解决方案
InputStream is = null;
try
{
is = new BufferedInputStream(new FileInputStream(Environment.getExternalStorageDirectory().getAbsolutePath() +"/Filename));
}
catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
while (is.available() > 0) {
bos.write(is.read());
}
}
catch (IOException e1) {
// TODO Auto-generated catch block
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
这篇关于使用KSOAP从Android应用程序文件传输到Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文