1

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

Taifun
  • 6,165
  • 17
  • 60
  • 188
m.rnry
  • 11
  • 3

2 Answers2

0

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.

Taifun
  • 6,165
  • 17
  • 60
  • 188
  • thanks for letting me know App Inventor does't work with that, I actually managed to make it work by using a php as a "bridge" between App Inventor and my web service and works fine. – m.rnry Apr 15 '18 at 02:07
  • you might want to add your solution as answer including your "bridge" php script ... this might help others with a similar question in future... thank you. – Taifun Apr 15 '18 at 19:41
0

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);
m.rnry
  • 11
  • 3