Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image file upload #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="output" path="build/classes"/>
</classpath>
31 changes: 31 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>wysiwyg-editor-java-sdk</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
7 changes: 7 additions & 0 deletions .settings/.jsdtscope
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
<classpathentry kind="src" path=""/>
<classpathentry kind="output" path=""/>
</classpath>
7 changes: 7 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
8 changes: 8 additions & 0 deletions .settings/org.eclipse.wst.common.component
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="wysiwyg-editor-java-sdk">
<wb-resource deploy-path="/" source-path="/WebContent" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>
<property name="context-root" value="wysiwyg-editor-java-sdk"/>
<property name="java-output-path" value="/wysiwyg-editor-java-sdk/build/classes"/>
</wb-module>
</project-modules>
5 changes: 5 additions & 0 deletions .settings/org.eclipse.wst.common.project.facet.core.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<installed facet="java" version="1.7"/>
<installed facet="jst.web" version="3.0"/>
</faceted-project>
1 change: 1 addition & 0 deletions .settings/org.eclipse.wst.jsdt.ui.superType.container
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.eclipse.wst.jsdt.launching.JRE_CONTAINER
1 change: 1 addition & 0 deletions .settings/org.eclipse.wst.jsdt.ui.superType.name
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Global
2 changes: 1 addition & 1 deletion Examples/WebContent/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
com.froala.examples.servlets.ContextListener
</listener-class>
</listener>
</web-app>
</web-app>
22 changes: 21 additions & 1 deletion Examples/WebContent/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ <h2>Sample 1: Save to disk</h2>
fileUploadParams: {
id: 'my_editor'
},
videoUploadURL: './upload_video',
videoUploadParams: {
id: 'my_editor'
},
imageManagerLoadURL: '/load_images',
imageManagerDeleteURL: "/delete_image",
imageManagerDeleteMethod: "POST"
Expand Down Expand Up @@ -120,7 +124,23 @@ <h2>Sample 1: Save to disk</h2>
.fail (function (err) {
console.log ('file delete problem: ' + JSON.stringify(err));
})
})
}),
$('#edit').on('froalaEditor.image.uploaded', function (e, editor, resp) {
console.log (resp)
var json = JSON.parse(resp);
console.log (json.link);
var img = new Image();
img.onerror = function () {
console.log ('error');
}
img.src = json.link;
})
$('#edit').on('froalaEditor.image.error', function (e, editor, error,response) {
console.log('this is e:', e);
console.log('this is editor:', editor);
console.log('this is error:', error);
console.log('this is error:', response);
});
});
</script>

Expand Down
1 change: 1 addition & 0 deletions Examples/build/classes/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/com/
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,5 @@ public void contextInitialized(ServletContextEvent event) {
if (!path.exists()) {
path.mkdirs();
}

System.out.println("Public folder is located here: " + publicFolderPath);
}
}
37 changes: 37 additions & 0 deletions Examples/src/com/froala/examples/servlets/FileServlet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.froala.examples.servlets;

import java.io.File;
import java.io.IOException;
import java.net.URLDecoder;
import java.nio.file.Files;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;




@WebServlet("/files/*")
public class FileServlet extends HttpServlet {

/**
*
*/
private static final long serialVersionUID = 1L;

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
String filename = URLDecoder.decode(request.getPathInfo().substring(1), "UTF-8");
File file = new File("/PATH TO/YOUR PROJECT/WORKSPACE/WEBCONTENT/WEB-INF/SOME FOLDER/", filename);
response.setHeader("Content-Type", getServletContext().getMimeType(filename));
response.setHeader("Content-Length", String.valueOf(file.length()));
response.setHeader("Content-Disposition", "inline; filename=\"" + file.getName() + "\"");
Files.copy(file.toPath(), response.getOutputStream());
}

}
2 changes: 1 addition & 1 deletion Examples/src/com/froala/examples/servlets/LoadImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public LoadImage() {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

String fileRoute = "/public/";
String fileRoute = "/PATH TO/YOUR PROJECT/WORKSPACE/WEBCONTENT/WEB-INF/SOME FOLDER/";
ArrayList<Object> responseData;
try {
responseData = Image.list(request, fileRoute);
Expand Down
2 changes: 1 addition & 1 deletion Examples/src/com/froala/examples/servlets/UploadFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public UploadFile() {
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

String fileRoute = "/public/";
String fileRoute = "/PATH TO/YOUR PROJECT/WORKSPACE/WEBCONTENT/WEB-INF/SOME FOLDER/";

// No validation.
FileOptions options = new FileOptions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public UploadFileValidation() {
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

String fileRoute = "/public/";
String fileRoute = "/PATH TO/YOUR PROJECT/WORKSPACE/WEBCONTENT/WEB-INF/SOME FOLDER/";

FileOptions options = new FileOptions();
options.setFieldname("myFile");
Expand Down
30 changes: 22 additions & 8 deletions Examples/src/com/froala/examples/servlets/UploadImage.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.froala.examples.servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -36,23 +37,36 @@ public UploadImage() {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

String fileRoute = "/PATH TO/YOUR PROJECT/WORKSPACE/WEBCONTENT/WEB-INF/SOME FOLDER/";
final PrintWriter writer = response.getWriter();

String fileRoute = "/public/";

Map<Object, Object> responseData;
Map<Object, Object> responseData = null;
try {
responseData = Image.upload(request, fileRoute); // Use default

responseData = Image.upload(request, fileRoute); // Use default
// image
// validation.

} catch (Exception e) {

e.printStackTrace();
responseData = new HashMap<Object, Object>();
responseData.put("error", e.toString());

} finally {

String jsonResponseData = new Gson().toJson(responseData);
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(jsonResponseData);

if (writer != null) {
writer.close();
}

}
String jsonResponseData = new Gson().toJson(responseData);
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(jsonResponseData);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public UploadImageResize() {
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

String fileRoute = "/public/";
String fileRoute = "/PATH TO/YOUR PROJECT/WORKSPACE/WEBCONTENT/WEB-INF/SOME FOLDER/";

// Use default validation with image resize;
ImageOptions options = new ImageOptions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public UploadImageValidation() {
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

String fileRoute = "/public/";
String fileRoute = "/PATH TO/YOUR PROJECT/WORKSPACE/WEBCONTENT/WEB-INF/SOME FOLDER/";

ImageOptions options = new ImageOptions();
options.setFieldname("myImage");
Expand Down
72 changes: 72 additions & 0 deletions Examples/src/com/froala/examples/servlets/UploadVideo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.froala.examples.servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.froala.editor.Video;
import com.google.gson.Gson;

/**
* Servlet implementation class UploadImage
*/
@WebServlet("/upload_video")
@MultipartConfig

public class UploadVideo extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public UploadVideo() {
super();
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

String fileRoute = "/PATH TO/YOUR PROJECT/WORKSPACE/WEBCONTENT/WEB-INF/SOME FOLDER/";
final PrintWriter writer = response.getWriter();

Map<Object, Object> responseData = null;
try {

responseData = Video.upload(request, fileRoute); // Use default
// image
// validation.

} catch (Exception e) {

e.printStackTrace();
responseData = new HashMap<Object, Object>();
responseData.put("error", e.toString());

} finally {

String jsonResponseData = new Gson().toJson(responseData);
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(jsonResponseData);

if (writer != null) {
System.out.println("writer is diff from null");
writer.close();
}

}

}
}
2 changes: 1 addition & 1 deletion Lib/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<classpathentry kind="lib" path="lib/gson-2.7-javadoc.jar"/>
<classpathentry kind="lib" path="lib/gson-2.7.jar"/>
<classpathentry kind="lib" path="lib/commons-codec-1.1.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="owner.project.facets" value="java"/>
</attributes>
Expand Down
6 changes: 3 additions & 3 deletions Lib/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.5
org.eclipse.jdt.core.compiler.source=1.7
2 changes: 0 additions & 2 deletions Lib/bin/.gitignore

This file was deleted.

Binary file modified Lib/bin/com/froala/editor/CustomValidation.class
Binary file not shown.
Binary file modified Lib/bin/com/froala/editor/File.class
Binary file not shown.
Binary file modified Lib/bin/com/froala/editor/Image.class
Binary file not shown.
Binary file modified Lib/bin/com/froala/editor/S3.class
Binary file not shown.
Binary file modified Lib/bin/com/froala/editor/Utils.class
Binary file not shown.
Binary file added Lib/bin/com/froala/editor/Video.class
Binary file not shown.
Binary file modified Lib/bin/com/froala/editor/file/FileOptions.class
Binary file not shown.
Binary file modified Lib/bin/com/froala/editor/file/FileValidation.class
Binary file not shown.
Binary file modified Lib/bin/com/froala/editor/image/ImageOptions$ResizeOptions.class
Binary file not shown.
Binary file modified Lib/bin/com/froala/editor/image/ImageOptions.class
Binary file not shown.
Binary file modified Lib/bin/com/froala/editor/image/ImageValidation.class
Binary file not shown.
Binary file modified Lib/bin/com/froala/editor/s3/S3Config.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading