Search code examples
javaweb-servicesapp-inventorform-parameterpostfile

How to send image from App Inventor to a java web service that uses FormDataParam


I've created a java web service that uploads an image to a folder. It works fine from a html form, but when i tried to send the image from app inventor using PostFile enter image description here

I get error 1104, which as I read means that either there's a problem with the url or with the internet connection. I know it's not my internet connection, so it has to be the url. I also noticed that in the web service the upload function requires a specific parameter enter image description here

that contains the image, I don't know if that's what's causing the problem or how to specify in App Inventor that the image belongs to that parameter like on a html form. enter image description here


Solution

  • As suggested by Taifun, here's my solution. I simply send my image from App Inventor to a php file that i have running on a http server and from that php i send the image to the java web service using curl, specifying the name of the parameter and using the file_get_contents('php://input') function to obtain the image received from App Inventor.

    $upload_url = 'http://192.168.1.77:8081/ImageProcessing/api/file/upload';
    $params = array(
     'photo'=>file_get_contents('php://input')
    );  
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_URL, $upload_url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
    $response = curl_exec($ch);
    
    echo $response;
    curl_close($ch);