内容简介:我尝试了几种不同的方法,没有任何正常的工作.代码日志版权声明:翻译自:http://stackoverflow.com/questions/4867007/playframework-ajax-drag-n-drop-file-upload-file-object-in-controller
我尝试了几种不同的方法,没有任何正常的工作.
这是我的成功尝试:
编辑路径文件并添加
POST /upload Application.upload
我们的控制器是应用程序,我将使用它来保持简单.
编辑您的应用程序控制器类
public static void upload(String qqfile) {
if (request.isNew) {
FileOutputStream moveTo = null;
Logger.info("Name of the file %s", qqfile);
// Another way I used to grab the name of the file
String filename = request.headers.get("x-file-name").value();
Logger.info("Absolute on where to send %s", Play.getFile("").getAbsolutePath() + File.separator + "uploads" + File.separator);
try {
InputStream data = request.body;
moveTo = new FileOutputStream(new File(Play.getFile("").getAbsolutePath()) + File.separator + "uploads" + File.separator + filename);
IOUtils.copy(data, moveTo);
} catch (Exception ex) {
// catch file exception
// catch IO Exception later on
renderJSON("{success: false}");
}
}
renderJSON("{success: true}");
}
在app / views / Application文件夹/包中编辑Application.html
#{extends 'main.html' /}
#{set title:'Multiple Uploads' /}
<div id="file-uploader">
<noscript>
<p>Please enable JavaScript to use file uploader.</p>
<!-- or put a simple form for upload here -->
</noscript>
<script>
function createUploader(){
var uploader = new qq.FileUploader({
element: document.getElementById('file-uploader'),
action: '/upload',
debug: true
});
}
// in your app create uploader as soon as the DOM is ready
// don't wait for the window to load
window.onload = createUploader;
</script>
</div>
编辑您的主要布局:main.html,位于app / views文件夹/包中,并在jQuery之后添加此行
<script src="@{'/public/javascripts/client/fileuploader.js'}" type="text/javascript"></script>
最后的笔记
记得从 AJAX Upload Valums 下载脚本,享受!
你也可以 grab the source here .
我在不同的浏览器中测试了它,至少对我来说是适用的.在Riyad玩的信用!邮件列表谁暗示了我有关请求
P.S:我正在使用我之前发表的评论
编辑
代码的答案已经按照T.J.的指示添加. Crowder,我同意:)
代码日志版权声明:
翻译自:http://stackoverflow.com/questions/4867007/playframework-ajax-drag-n-drop-file-upload-file-object-in-controller
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- 自定义MVC框架 -封装控制器层
- 自定义MVC框架-封装控制器基类
- iOS之导航返回上上个控制器或指定返回某个控制器
- iOS小技巧·把子视图控制器的视图添加到父视图控制器
- javascript – AngularJS控制器错误 – :$http.get不是控制器部分的函数
- AC敏捷控制器及准入控制技术对比
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Artificial Intelligence
Stuart Russell、Peter Norvig / Pearson / 2009-12-11 / USD 195.00
The long-anticipated revision of this #1 selling book offers the most comprehensive, state of the art introduction to the theory and practice of artificial intelligence for modern applications. Intell......一起来看看 《Artificial Intelligence》 这本书的介绍吧!
图片转BASE64编码
在线图片转Base64编码工具
HEX HSV 转换工具
HEX HSV 互换工具