使用REST或Web服务上载/下载文件

是否可以使用REST或任何其他Web服务上传/下载文件并发送HTML代码?

这可以使用:PHP,Java或ASP。

我认为这会有所帮助。 至少在Java方面。 Actualy,看看整个教程

以下是使用Spring执行此操作的示例:

将commons-io和commons-fileupload依赖项添加到pom.xml 。 在servlet上下文xml文件中配置多部分解析程序:

    

这将是您上传文件的JSP(即fileUpload.jsp ):

 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>         

这是控制器:

 import java.io.IOException; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.servlet.ModelAndView; @Controller public class UploadController { // Show page for upload @RequestMapping(value = "/fileUpload", method = RequestMethod.GET) public ModelAndView showUploadFilePage() { return new ModelAndView("fileUpload", "upload", null); } // Get multipart file and save it @RequestMapping(value = "/uploadNewFile", method = RequestMethod.POST) public String save(@RequestParam("file") MultipartFile file) { // Save it to ie database // dao.save(file); return "fileUpload"; } // Downloads file. Ie JPG image @RequestMapping(value = "/download/{id}", produces = MediaType.IMAGE_JPEG_VALUE) public @ResponseBody HttpEntity getFile( @PathVariable("id") Integer id) throws IOException { byte[] file= dao.get(id).getImage(); HttpHeaders header = new HttpHeaders(); header.set("Content-Disposition", "attachment; filename=Image"); header.setContentLength(file.length); return new HttpEntity(file, header); } } 

是的……它可能。

这取决于服务器端的实现。

但如果你只是想要一个答案……那就是YES

http://blogs.msdn.com/b/uksharepoint/archive/2013/04/20/uploading-files-using-the-rest-api-and-client-side-techniques.aspx

是的它可能,需要使用正确的mimetype来实现这一点。 如果你使用Rest,你可以在响应体中传递字符串…