简体   繁体   English

如何通过JAX-RS(Jersey)使用$ resource从AngularJS客户端使用JSON数据和文件上传向服务器发送请求?

[英]How can I send request to the server with JSON data and fileupload from AngularJS client using $resource via JAX-RS(Jersey)?

I want to send a request the request to the server with JSON data and an Image file in a single request via JAX-Rs. 我想通过JAX-R在单个请求中将请求与JSON数据和一个图像文件一起发送到服务器。 Using AngularJS $resource. 使用AngularJS $ resource。

Unfortunately this isn't possible. 不幸的是,这是不可能的。 You can upload an image to the server with AJAX, if you target the very latest browsers by using XmlHttpRequest2 , but you still won't be able to upload both image data and JSON in one request. 如果使用XmlHttpRequest2定位最新的浏览器,则可以使用AJAX将图像上传到服务器,但是仍然不能在一个请求中同时上传图像数据和JSON Generally this is handled by uploading a file inside an iframe and then triggering something in your angular app once the upload is complete. 通常,这是通过在iframe上传文件,然后在上传完成后触发您的角度应用程序中的内容来解决的。

If you google "angular file upload" there are numerous libraries that can help with this. 如果您用谷歌“角度文件上传”,有很多图书馆可以帮助您。

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

相关问题 如何通过JAX-RS(Jersey)从客户端获取带有JSON数据和文件上传的请求? - How can I get request from the client with JSON data and fileupload via JAX-RS(Jersey)? 如何在发布请求中使用 jersey(jax-rs) 客户端将 object 作为另一个 object 的属性传递? - How to pass an object as an attribute of another object using jersey(jax-rs) client in a post request? 如何使用 Jersey (JAX-RS) 向 NTLM 身份验证服务器发出简单的 POST 请求 - How to Make a Simple POST Request Using Jersey (JAX-RS) to NTLM Authenticated Server JAX-RS / Jersey:如何“继承” @Provider字段? - JAX-RS/Jersey: How can I “inherit” @Provider fields? 如何使用http POST JAX-RS将对象从AngularJS服务传递给Java - How can I pass an Object from an AngularJS Service to Java using http POST JAX-RS 如何使用Jersey JAX-RS返回结果集? - How do I return a resultset using Jersey JAX-RS? 如何使用JAX-RS(Jersey)编写服务器端Java代码以将任何类型的文件作为流返回? - How can I write a server side java code to return any kind of file as stream using JAX-RS(Jersey)? 如何使用JAX-RS从Java服务器端返回Zip文件? - How can I return a Zip file from my Java server-side using JAX-RS? 泽西岛/ JAX-RS客户抛出400错误请求 - Jersey/JAX-RS Client throwing 400 Bad Request 客户端超时未完成Jersey JAX-RS 1.0请求 - Jersey JAX-RS 1.0 request not completed with client timesout
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM