0
처음에는 파일 업로드를위한 자바 스크립트 기능을 구현하려고했지만 파일이 업로드되지 않으며 해당 코드로 게임하는 방법을 알 수 없습니다.Play 프레임 워크에서 이미지 업로드
이것은 "보기 파일"입니다 :
<div id="file-uploader">
<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>
는이 컨트롤러입니다 :
package controllers;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import models.Photo;
import models.User;
import play.*;
import play.mvc.*;
import org.apache.commons.io.IOUtils;
public class Uploader extends Controller {
public static Long id;
public static void index(Long id) {
System.out.println("this is id inside the tester"+id);
new Uploader(id);
render();
}
public Uploader(Long id) {
this.id = id;
}
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 {
String filelocation = File.separator + "uploads" + File.separator + filename;
InputStream data = request.body;
moveTo = new FileOutputStream(new File(Play.getFile("").getAbsolutePath())
+ File.separator + "uploads" + File.separator + filename);
IOUtils.copy(data, moveTo);
Users.show(id);
} catch (Exception ex) {
// catch file exception
// catch IO Exception later on
renderJSON("{success: false}");
System.out.println("Exception is:" + ex);
}
}
}
}
나는 그것을 사용자 정의 할 (예 : 업로드 기능에 더 많은 매개 변수를 전달) 할 수는 없지만 그 일을하는 방법을 찾으십시오.
내가 잘못하고있는 곳을 말해 주시겠습니까? 가능하다면 양식을 통해 파일을 업로드하도록 안내해 줄 수 있습니까?
나는 이것이 좋은 질문이라고 생각하지만 난 거입니다 당신이 그 프리젠 테이션을 바꿀 것을 제안하십시오. 1) 시도한 링크를 추가하십시오. 실패한 예를 보여줍니다. 2) 질문을 다시 적게하여 덜 까다로운 소리를 들으십시오. –