简体   繁体   English

如何将图像从App Inventor发送到使用FormDataParam的Java Web服务

[英]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. 我创建了一个Java Web服务,将图像上传到文件夹。 It works fine from a html form, but when i tried to send the image from app inventor using PostFile 它可以从html表单正常工作, 但是当我尝试使用PostFile从App Inventor发送图像时 在此处输入图片说明

I get error 1104, which as I read means that either there's a problem with the url or with the internet connection. 我收到错误1104,据我所读,它意味着URL或Internet连接有问题。 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 我还注意到,在Web服务中,上传功能需要特定的参数 在此处输入图片说明

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 . 包含图片的图片,我不知道这是导致问题的原因,还是在App Inventor中如何指定图片属于该参数(如html表单) 在此处输入图片说明

Unfortunately the web component of App Inventor is not able to understand multipart/formdata . 不幸的是,App Inventor的Web组件无法理解multipart/formdata

You can upload a file to your web server using the PostFile method see this example , alternatively use the ftp extension . 您可以使用PostFile方法将文件上传到Web服务器, 请参见本示例 ,或者使用ftp扩展名

As suggested by Taifun, here's my solution. 正如Taifun所建议的,这是我的解决方案。 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. 我只是将图像从App Inventor发送到我在http服务器上运行的php文件中,然后从该php中使用curl ,指定参数名称并使用file_get_contents('php: // input')函数来获取从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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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