convertire il file immagine in una stringa Base64 e inviare la stringa con il suo nome al web-service con facilità. Hai ancora bisogno di un esempio di codice?
Modifica
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;
}
inviare il tuo oggetto al webservice come una stringa JSON:
nella vostra attività:
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
//...
}
Nel vostro webservice convertire la stringa JSON per un vero e proprio oggetto che è una replica di MyClass.
edit:
Inoltre si può ignorare JSON e avere un metodo webserivce con 2 parametri: MyWebserviceMethod(string filename, string content);
passaggio stringa Base64 come secondo parametro.
OK, come è possibile convertirlo in Base64 e come riconvertirsi in file immagine sul server? Ho trovato poche informazioni per l'utilizzo di DataHandler - che è meglio? Un bel esempio di codice breve sarà davvero grandioso. Grazie – Yoav
Gson può essere usato con SoapObject? Sto usando SoapObject c; ... c.adppProperty (...). Dovrei mettere la Base^$ info come una proprietà? – Yoav
come implementate il vostro servizio web? è un servizio web .Net? – breceivemail