上传图片从机器人到web服务 [英] upload image from android to webservice

查看:158
本文介绍了上传图片从机器人到web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用SOAP我如何上传图片文件到web服务?

How can I upload an image file to a webservice using SOAP?

我需要它与SoapObejct使用这样的Web服务可以处理在其范围内的输入文件,并给它一个新的文件名。

I need it to be used with SoapObejct so the webservice can handle the input file in its context and give it a new filename.

如何? 任何code的例子吗?

How? Any code examples?

约阿夫

推荐答案

图像文件转换为Base64的字符串,其名称的网络服务很容易地把你的字符串。 你还需要code样?

Convert your image file to a Base64 string and send your string with its name to web-service easily. Do you still need code sample?

修改

public static String fileToBase64(String path) throws IOException {
    byte[] bytes = Utilities.fileToByteArray(path);
    return Base64.encodeBytes(bytes);
}

public static byte[] fileToByteArray(String path) throws IOException {
    File imagefile = new File(path);
    byte[] data = new byte[(int) imagefile.length()];
    FileInputStream fis = new FileInputStream(imagefile);
    fis.read(data);
    fis.close();
    return data;
}

public class MyImage  {
public String name;
public String content;
}

把你的对象给web服务作为一个JSON字符串:

send your object to the webservice as a JSON string:

在您的活动:

MyClass myClass = new MyClass();
myClass.name = "a.jpg";
myClass.content = fileToBase64("../../image.jpg");
sendMyObject(myClass);

private void sendMyObject(
        MyImage myImage ) throws Exception {
    // create json string from your object
    Gson gson = new Gson();
    String strJson = gson.toJson(myImage);
    //send your json string here
    //...

}

在您的Web服务将您的JSON字符串是MyClass的副本的真正对象。

In your webservice convert your json string to a real object which is a replica of MyClass.

编辑:

你也可以忽略JSON和有webserivce方法有两个参数: MyWebserviceMethod(字符串的文件名,字符串内容); 通过Base64的字符串作为第二个参数。

Also you can ignore Json and have a webserivce method with 2 parameters: MyWebserviceMethod(string filename, string content); pass Base64 string as second parameter.

这篇关于上传图片从机器人到web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆