Phonegap FileTransfer 通过https协议上传文件
2014-03-20 16:05
309 查看
1、upload的第五个参数是 是否debug模式的意思,设置为true。但是如果你的https链接已经购买了SSL证书,则建议还是把debug关闭。
我的后台是java的,采用commons-fileupload.-1.0.jar,但报错:
org.apache.commons.fileupload.FileUploadBase$UnknownSizeException: the request was rejected because it's size is unknown
phonegap的官网说FileTransfer是支持http和https两种协议的,所以我猜想是不是commons-fileupload的版本太低,尝试换了1.2.2的版本,果然可以了。
如果报:java.lang.ClassNotFoundException: org.apache.commons.io.output.DeferredFileOutputStream 错误,请把commons-io-2.0.1.jar也配上。
附上我后台处理的代码,原本有点复杂,简化一下,如下:
记得还要给你这个Action配上ActionForm!
var ft = new FileTransfer(); ft.upload(fileURI, encodeURI(url), function() { //alert('上传成功!'); }, function() { //alert('上传失败!'); }, options,true);
我的后台是java的,采用commons-fileupload.-1.0.jar,但报错:
org.apache.commons.fileupload.FileUploadBase$UnknownSizeException: the request was rejected because it's size is unknown
phonegap的官网说FileTransfer是支持http和https两种协议的,所以我猜想是不是commons-fileupload的版本太低,尝试换了1.2.2的版本,果然可以了。
如果报:java.lang.ClassNotFoundException: org.apache.commons.io.output.DeferredFileOutputStream 错误,请把commons-io-2.0.1.jar也配上。
附上我后台处理的代码,原本有点复杂,简化一下,如下:
public ActionForward uploadPic(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { try{ Hashtable files = form.getMultipartRequestHandler().getFileElements(); FormFile formFile=null; for(Enumeration e = files.keys(); e.hasMoreElements();){ String inputName = (String) e.nextElement(); formFile = (FormFile)files.get(inputName); try { byte[] filebyte = formFile.getFileData(); String fileName = formFile.getFileName(); //保存文件,写你保存文件的逻辑 } catch (FileNotFoundException e1) { log.error(e1.getMessage(),e1); } catch (IOException e1) { log.error(e1.getMessage(),e1); } if (formFile==null||formFile.getFileSize() <= 0) { continue; } } }catch(Exception e){ log.error(e.getMessage(),e); } return null; }
记得还要给你这个Action配上ActionForm!
相关文章推荐
- java网络编程:通过HTTPS协议传送xml文件交互
- file 标签上传文件,直接样式太难看!隐藏它,通过别的按钮触发它,又会有IE兼容问题。
- 使用插件ajaxfileupload通过ajax方式上传文件,在火狐下出错
- 如何通过脚本给 文件上传输入的file控件赋值
- SSH Secure File Transfer上传文件错误:encountered 1 errors during the transfer解决办法
- 通过 http 协议上传文件
- 通过 http 协议上传文件(rfc1867协议概述,jsp 应用举例,客户端发送内容构造)
- cordova-plugin-file-transfer实现文件上传、下载整理(一)
- Asp.net网站中 js通过input type="file" 上传文件
- 通过HtmlInputFile控件上传文件的类
- asp.net 通过HtmlInputFile控件上传文件的类
- android http通过post上传文件和提交参数(通过拼装协议)
- 关于$cordovaFileTransfer上传文件和参数遇到的坑
- 通过 http 协议上传文件(rfc1867协议概述,jsp 应用举例,客户端发送内容构造)
- 通过 http 协议上传文件(rfc1867协议概述,jsp 应用举例,客户端发送内容构造)
- $cordovaFileTransfer 拍照上传文件
- 通过 http 协议上传文件
- 通过HtmlInputFile控件上传文件的类
- 文件上传下载——通过struts的FormFile上传单个excel文件
- jsp页面通过uploadfile工具上传文件