简体   繁体   中英

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 在此处输入图片说明

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 在此处输入图片说明

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 . 在此处输入图片说明

Unfortunately the web component of App Inventor is not able to understand multipart/formdata .

You can upload a file to your web server using the PostFile method see this example , alternatively use the ftp extension .

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM