서버에 파일을 업로드하는 방법에 대한 좋은 예를 찾을 수 있습니다 here.
편집이
당신이해야 할 것은, 서버에 이미지를 업로드 클라이언트에서 검색, 클라이언트에서 시각적으로 자르기를 수행 서버로 자르기 매개 변수를 보내는 것입니다, 그리고 마지막으로 실제 일을 서버에서 자르기. 사용자가 이미지를 선택
vPanel.add(new Button("Submit", new ClickHandler() {
public void onClick(ClickEvent event) {
form.submit();
}
}));
하면, 우리는는 FileUpload와 함께 업로드, 서버에 우리가 디렉토리에 저장 :이 프로젝트는 위에서 언급 한에서 나는 그것이 시작하려면 관리하는 방법입니다
업로드 된 경우 다시 클라이언트에
protected void doGet(HttpServletRequest req,
HttpServletResponse resp) throws ServletException,
IOException
{
resp.setContentType("image/jpeg");
ServletOutputStream out = resp.getOutputStream();
BufferedInputStream bis= new BufferedInputStream(new FileInputStream(<images-path>+req.getParameter("name")));
BufferedOutputStream bos = new BufferedOutputStream(resp.getOutputStream());
int ch;
while((ch=bis.read())!=-1)
{
bos.write(ch);
}
bis.close();
bos.flush();
bos.close();
out.close();
}
:
List<FileItem> items = fileUpload.parseRequest(request);
Iterator<FileItem> iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
File file = new File(<images-path>,fileName);
Streams.copy(item.getInputStream(),new FileOutputStream(file), true);
}
우리는 우리가 get 메소드를 소요하고 이미지를 반환하는 서블릿을 추가 할 수 있도록 업로드 된 이미지를 검색하는 서비스를 필요 작업이 완료되면 업로드 된 이미지의 복사본을 검색하여 양식 제출 처리기를 추가하려고합니다. 나는 시각 단계에서이 gwt cropping library을 사용하고 있습니다 :
form.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler()
{
public void onSubmitComplete(SubmitCompleteEvent event)
{
Element label = DOM.createLabel();
label.setInnerHTML(event.getResults());
String result = label.getInnerText(); // result contains the name of the image in the server
final GWTCropper crop = new GWTCropper(GWT.getModuleBaseURL()+"image?name="+result);
crop.setAspectRatio(1);
vPanel.add(crop);
}
}
지금 우리가 내가 할 수있는 RCP 서비스를 사용하는 서버에서 발생하는 실제 자르기를 할 수있는 자르기 서비스를 추가 할 수 있습니다
public class CropServiceImpl extends RemoteServiceServlet implements CropService {
public Boolean crop(String name, int x, int y, int width, int height)
{
try
{
BufferedImage outImage = ImageIO.read(new File("<images-path>"+name));
BufferedImage cropped = outImage.getSubimage(x, y, width, height);
ImageIO.write(cropped, "jpg", new File("<images-path>","cropped"+name));
return true;
}
catch (IOException e)
{
e.printStackTrace();
}
return false;
}
}
vPanel.add(new Button("Crop", new ClickHandler()
{
public void onClick(ClickEvent event)
{
cropService.crop(getName(), (int) crop.getSelectionXCoordinate(),
(int) crop.getSelectionYCoordinate(), (int) crop.getSelectionWidth(),
(int) crop.getSelectionHeight(), new AsyncCallback<Boolean>()
{
public void onFailure(Throwable arg0)
{
// something went wrong with the call
}
public void onSuccess(Boolean arg0)
{
if (arg0)
{
// the cropped file now lives in the server
}
else
{
// an error happened in the server
}
}
});
}
}));
을 거기에 당신이 긴 포를 들어, 미안 이동 :
마지막으로, 다시 클라이언트에, 우리는 우리가 자르기에서 얻을 매개 변수와 버튼 액션 내부의 메소드를 호출 도움이되기를 바랍니다.
업로드 방법을 지정해야합니다. –
파일 업로드 솔루션을 찾고 있다면 [Apache Commons File Upload] (http://commons.apache.org/proper/commons-fileupload/using.html)를 사용할 수 있습니다. – Churro
업로드 할 수있는 유일한 방법은 파일 (클라이언트 사이트에서)은 FormPanel 및 Fileupload 위젯을 통해 전송됩니다. 그러나 이것은 단지 파일 관리자를 사용하여 사용자가 선택한 파일을 업로드 할 수는 있지만 앱이 수정 한 이미지는 업로드 할 수 없습니다 (크 루프 이미지). 내가 찾고있는 것은 그것을하는 방법이다. –