-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UD-806 Allow to drag and drop local files to the Che instance
Change-Id: I18d33c9f9abb3ee5c70504a14e36a39a1056a224 Signed-off-by: Florent BENOIT <fbenoit@codenvy.com>
- Loading branch information
Showing
14 changed files
with
293 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
che-admin-war/src/main/java/org/eclipse/che/admin/deploy/Constants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012-2015 Codenvy, S.A. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Codenvy, S.A. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.che.admin.deploy; | ||
|
||
/** | ||
* Constants that might be defined in che.properties file. | ||
* @author Florent Benoit | ||
*/ | ||
public class Constants { | ||
|
||
/** | ||
* Constant used to describe the path to the servlet upload directory when uploading files. | ||
*/ | ||
public static final String CHE_SERVLET_UPLOAD_DIRECTORY = "che.servlet.upload.directory"; | ||
} |
79 changes: 79 additions & 0 deletions
79
che-admin-war/src/main/java/org/eclipse/che/admin/upload/UploadServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012-2015 Codenvy, S.A. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Codenvy, S.A. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.che.admin.upload; | ||
|
||
import org.eclipse.che.admin.deploy.Constants; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
import javax.inject.Singleton; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.annotation.MultipartConfig; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
/** | ||
* Upload servlet allowing to upload files to the server. Request should contain a part named 'uploadedFile' for the file. | ||
* @author Florent Benoit | ||
*/ | ||
@MultipartConfig | ||
@Singleton | ||
public class UploadServlet extends HttpServlet { | ||
|
||
/** | ||
* Serializable class; | ||
*/ | ||
private static final long serialVersionUID = -687991492884005033L; | ||
|
||
/** | ||
* Folder used to store uploaded files. | ||
*/ | ||
private String uploadFolder; | ||
|
||
/** | ||
* Create a new upload folder. | ||
* @param uploadFolder the path to store the uploaded files. | ||
*/ | ||
@Inject | ||
public UploadServlet(@Named(Constants.CHE_SERVLET_UPLOAD_DIRECTORY) String uploadFolder) { | ||
this.uploadFolder = uploadFolder; | ||
} | ||
|
||
/** | ||
* Handle the POST request only by allowing to upload files. | ||
* @param request the request with a part named 'uploadedFile' | ||
* @param response empty if file is uploaded | ||
* @throws ServletException if there is a problem while uploading | ||
* @throws IOException if there is a problem while uploading | ||
*/ | ||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||
request.getParts().stream().forEach((filePart -> { | ||
try { | ||
String fileName = filePart.getSubmittedFileName(); | ||
InputStream inputStream = filePart.getInputStream(); | ||
Path path = Paths.get(uploadFolder).resolve(fileName); | ||
Files.createDirectories(path.getParent()); | ||
Files.copy(inputStream, path); | ||
|
||
} catch (IOException e) { | ||
throw new RuntimeException("Unable to upload files", e); | ||
} | ||
})); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2012-2015 Codenvy, S.A. | ||
All rights reserved. This program and the accompanying materials | ||
are made available under the terms of the Eclipse Public License v1.0 | ||
which accompanies this distribution, and is available at | ||
http://www.eclipse.org/legal/epl-v10.html | ||
Contributors: | ||
Codenvy, S.A. - initial API and implementation | ||
--> | ||
<Context allowCasualMultipartParsing="true" /> |
13 changes: 13 additions & 0 deletions
13
che-admin-war/src/main/webapp/WEB-INF/classes/che/che.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# | ||
# Copyright (c) 2012-2015 Codenvy, S.A. | ||
# All rights reserved. This program and the accompanying materials | ||
# are made available under the terms of the Eclipse Public License v1.0 | ||
# which accompanies this distribution, and is available at | ||
# http://www.eclipse.org/legal/epl-v10.html | ||
# | ||
# Contributors: | ||
# Codenvy, S.A. - initial API and implementation | ||
# | ||
|
||
# Directory used to upload files | ||
che.servlet.upload.directory=${catalina.base}/temp/upload |
18 changes: 18 additions & 0 deletions
18
examples/my-multi-extension/my-action/src/main/resources/tutorial/MyExtension.gwt.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!-- | ||
Copyright (c) 2012-2015 Codenvy, S.A. | ||
All rights reserved. This program and the accompanying materials | ||
are made available under the terms of the Eclipse Public License v1.0 | ||
which accompanies this distribution, and is available at | ||
http://www.eclipse.org/legal/epl-v10.html | ||
Contributors: | ||
Codenvy, S.A. - initial API and implementation | ||
--> | ||
<module> | ||
<inherits name="com.google.gwt.user.User"/> | ||
<inherits name="org.eclipse.che.ide.Api"/> | ||
<inherits name="com.google.gwt.inject.Inject"/> | ||
<source path=""/> | ||
</module> |
18 changes: 18 additions & 0 deletions
18
examples/my-project-type/src/main/resources/tutorial/MyExtension.gwt.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!-- | ||
Copyright (c) 2012-2015 Codenvy, S.A. | ||
All rights reserved. This program and the accompanying materials | ||
are made available under the terms of the Eclipse Public License v1.0 | ||
which accompanies this distribution, and is available at | ||
http://www.eclipse.org/legal/epl-v10.html | ||
Contributors: | ||
Codenvy, S.A. - initial API and implementation | ||
--> | ||
<module> | ||
<inherits name="com.google.gwt.user.User"/> | ||
<inherits name="org.eclipse.che.ide.Api"/> | ||
<inherits name="com.google.gwt.inject.Inject"/> | ||
<source path=""/> | ||
</module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.