You haven’t told us the format your server is expecting. Usually with form submit you send the images as binary data not base 64 strings, but it’s impossible to know that without knowing your server.
You are correct in not using the file transfer plugin, it should not be used any longer, it has been deprecated.
Okay, that’s a good start. Now, we need to know what’s actually happening with this, can you:
Show any code from the getPictures() method
Show any code that accesses #mulupoad
When you actually upload the file and it works, using Chrome debug tools go to the Network tab, find the actual POST request in the list of requests, click on it, and show us the ‘Request Payload’ section. If you can do that…we should be able to actually determine the data format your server expects…since…you still haven’t just told us. The section I’m looking for looks like this.
Perfect. So, just as I thought, your server is expecting the binary file data, which you properly send in your web code. But then in your cordova code you are sending strings…so…it doesn’t work.
Luckily my blog post I posted earlier in this thread does literally exactly what you want so you can just follow that and you’ll have it working. The only difference is that my server expects it to be named ‘photos’ (plural), while yours expects ‘photo’ singular, and I send the filename to my server and you don’t.
So, just follow my blog post all the way through, but anywhere you see formData.append, send it ‘photo’ instead of ‘photos’ and don’t send the file name along. Otherwise it will work perfectly.
public sendImage(base64Image: string){
let fd:FormData = new FormData();
fd.append(‘photo’, base64Image);
//URL post
var service_url =this.urlpath+‘processImage’;
return this.http.post(service_url,fd);
}
Java code
Pay attention to “FormDataParam” have the same name in your server and ionic post code!!!
@POST @Path("/processImage") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.MULTIPART_FORM_DATA)
//@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response processImage(@Context HttpHeaders httpHeaders, @FormDataParam(“photo”) String photo) throws IOException{
//photo is a String B64, yo need decode an save
return Response.status(Response.Status.OK).
entity(responseObj(true,“My message”)).
header(“Access-Control-Allow-Origin”, “*”).build();
I have a problem in uploading images, requirement is to send with binary data but somehow, I tested using […binarydata…] it shows as a blank image in server but if I tested using .bin file type it shows up correctly,
I am using the postman for trial but I am not sure on how can I achieve generate a bin file via ionic, is there any reference on this?