file upload ground base complete
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/sbd-uploadshare-portlet@164571 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
a14dfeabb4
commit
77454a130d
|
@ -0,0 +1,67 @@
|
|||
package org.gcube.portlets.user.sbd;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import javax.portlet.ActionRequest;
|
||||
import javax.portlet.ActionResponse;
|
||||
import javax.portlet.PortletException;
|
||||
import javax.portlet.PortletRequest;
|
||||
import javax.portlet.ResourceRequest;
|
||||
import javax.portlet.ResourceResponse;
|
||||
|
||||
import com.liferay.portal.kernel.exception.PortalException;
|
||||
import com.liferay.portal.kernel.exception.SystemException;
|
||||
import com.liferay.portal.kernel.json.JSONFactoryUtil;
|
||||
import com.liferay.portal.kernel.json.JSONObject;
|
||||
import com.liferay.portal.kernel.upload.FileItem;
|
||||
import com.liferay.portal.kernel.upload.UploadPortletRequest;
|
||||
import com.liferay.portal.kernel.util.FileUtil;
|
||||
import com.liferay.portal.util.PortalUtil;
|
||||
import com.liferay.util.bridges.mvc.MVCPortlet;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Portlet implementation class FileUpload
|
||||
*/
|
||||
public class FileUpload extends MVCPortlet {
|
||||
private final static String UPLOADED_FILE_ATTR_NAME = "myfile";
|
||||
//make sure in the jsp there's <portlet:resourceURL var="uploadFileURL" id="uploadFiles" />
|
||||
private final static String RESOURCE_URL_ID = "uploadFiles";
|
||||
|
||||
|
||||
@Override
|
||||
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws PortletException, IOException {
|
||||
String resourceID = resourceRequest.getResourceID();
|
||||
if (resourceID.equals(RESOURCE_URL_ID)) {
|
||||
System.out.println("here test uploadFiles");
|
||||
UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(resourceRequest);
|
||||
File multipartFile = uploadRequest.getFile(UPLOADED_FILE_ATTR_NAME);
|
||||
|
||||
FileItem[] items = uploadRequest.getMultipartParameterMap().get(UPLOADED_FILE_ATTR_NAME);
|
||||
String fileName = "";
|
||||
String contentType = "";
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
fileName = items[i].getFileName();
|
||||
contentType = items[i].getContentType();
|
||||
System.out.println(fileName);
|
||||
System.out.println(contentType);
|
||||
}
|
||||
Path written = Files.write(Paths.get(System.getProperty("catalina.home")+"/temp/"+fileName), FileUtil.getBytes(multipartFile));
|
||||
System.out.println("Written File = " + written.toRealPath());
|
||||
JSONObject fileObject = JSONFactoryUtil.createJSONObject();
|
||||
fileObject.put("fileid", "12345");
|
||||
resourceResponse.getWriter().println(fileObject);
|
||||
|
||||
} else {
|
||||
System.out.println("it's another method");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -12,5 +12,6 @@
|
|||
<category name="gCube Applications">
|
||||
<portlet id="access-exploratory"></portlet>
|
||||
<portlet id="access-application"></portlet>
|
||||
<portlet id="file-upload"></portlet>
|
||||
</category>
|
||||
</display>
|
|
@ -49,6 +49,12 @@
|
|||
access-application-portlet
|
||||
</css-class-wrapper>
|
||||
</portlet>
|
||||
<portlet>
|
||||
<portlet-name>file-upload</portlet-name>
|
||||
<icon>/icon.png</icon>
|
||||
<header-portlet-css>/css/main.css</header-portlet-css>
|
||||
<css-class-wrapper>file-upload-portlet</css-class-wrapper>
|
||||
</portlet>
|
||||
<role-mapper>
|
||||
<role-name>administrator</role-name>
|
||||
<role-link>Administrator</role-link>
|
||||
|
|
|
@ -143,4 +143,37 @@
|
|||
<role-name>user</role-name>
|
||||
</security-role-ref>
|
||||
</portlet>
|
||||
<portlet>
|
||||
<portlet-name>file-upload</portlet-name>
|
||||
<display-name>File Upload</display-name>
|
||||
<portlet-class>
|
||||
org.gcube.portlets.user.sbd.FileUpload
|
||||
</portlet-class>
|
||||
<init-param>
|
||||
<name>view-template</name>
|
||||
<value>/html/fileupload/view.jsp</value>
|
||||
</init-param>
|
||||
<expiration-cache>0</expiration-cache>
|
||||
<supports>
|
||||
<mime-type>text/html</mime-type>
|
||||
<portlet-mode>view</portlet-mode>
|
||||
</supports>
|
||||
<portlet-info>
|
||||
<title>File Upload</title>
|
||||
<short-title>File Upload</short-title>
|
||||
<keywords></keywords>
|
||||
</portlet-info>
|
||||
<security-role-ref>
|
||||
<role-name>administrator</role-name>
|
||||
</security-role-ref>
|
||||
<security-role-ref>
|
||||
<role-name>guest</role-name>
|
||||
</security-role-ref>
|
||||
<security-role-ref>
|
||||
<role-name>power-user</role-name>
|
||||
</security-role-ref>
|
||||
<security-role-ref>
|
||||
<role-name>user</role-name>
|
||||
</security-role-ref>
|
||||
</portlet>
|
||||
</portlet-app>
|
|
@ -9,3 +9,151 @@
|
|||
font-size: 14px;
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
/* file upload css */
|
||||
.ajax-file-upload-statusbar {
|
||||
border: 1px solid #0ba1b5;
|
||||
margin-top: 10px;
|
||||
width: 420px;
|
||||
margin-right: 10px;
|
||||
margin: 5px;
|
||||
-moz-border-radius: 4px;
|
||||
-webkit-border-radius: 4px;
|
||||
border-radius: 4px;
|
||||
padding: 5px 5px 5px 15px
|
||||
}
|
||||
|
||||
.ajax-file-upload-filename {
|
||||
width: 300px;
|
||||
height: auto;
|
||||
margin: 0 5px 5px 0px;
|
||||
}
|
||||
|
||||
.ajax-file-upload-filesize {
|
||||
width: 50px;
|
||||
height: auto;
|
||||
margin: 0 5px 5px 0px;
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.ajax-file-upload-progress {
|
||||
margin: 5px 10px 5px 0px;
|
||||
position: relative;
|
||||
width: 250px;
|
||||
border: 1px solid #ddd;
|
||||
padding: 1px;
|
||||
border-radius: 3px;
|
||||
display: inline-block;
|
||||
color: #FFFFFF;
|
||||
}
|
||||
|
||||
.ajax-file-upload-bar {
|
||||
background-color: #0ba1b5;
|
||||
width: 0;
|
||||
height: 20px;
|
||||
border-radius: 3px;
|
||||
color: #FFFFFF;
|
||||
}
|
||||
|
||||
.ajax-file-upload-percent {
|
||||
position: absolute;
|
||||
display: inline-block;
|
||||
top: 3px;
|
||||
left: 48%
|
||||
}
|
||||
|
||||
.ajax-file-upload-red {
|
||||
-moz-box-shadow: inset 0 39px 0 -24px #e67a73;
|
||||
-webkit-box-shadow: inset 0 39px 0 -24px #e67a73;
|
||||
box-shadow: inset 0 39px 0 -24px #e67a73;
|
||||
background-color: #e4685d;
|
||||
-moz-border-radius: 4px;
|
||||
-webkit-border-radius: 4px;
|
||||
border-radius: 4px;
|
||||
display: inline-block;
|
||||
color: #fff;
|
||||
font-family: arial;
|
||||
font-size: 13px;
|
||||
font-weight: normal;
|
||||
padding: 4px 15px;
|
||||
text-decoration: none;
|
||||
text-shadow: 0 1px 0 #b23e35;
|
||||
cursor: pointer;
|
||||
vertical-align: top;
|
||||
margin: 5px 10px 5px 0px;
|
||||
}
|
||||
|
||||
.ajax-file-upload-green {
|
||||
background-color: #77b55a;
|
||||
-moz-border-radius: 4px;
|
||||
-webkit-border-radius: 4px;
|
||||
border-radius: 4px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: inline-block;
|
||||
color: #fff;
|
||||
font-family: arial;
|
||||
font-size: 13px;
|
||||
font-weight: normal;
|
||||
padding: 4px 15px;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
text-shadow: 0 1px 0 #5b8a3c;
|
||||
vertical-align: top;
|
||||
margin: 5px 10px 5px 0px;
|
||||
}
|
||||
|
||||
.ajax-file-upload {
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
padding: 15px 20px;
|
||||
cursor: pointer;
|
||||
line-height: 20px;
|
||||
height: 25px;
|
||||
margin: 0 10px 10px 0;
|
||||
display: inline-block;
|
||||
background: #fff;
|
||||
border: 1px solid #e8e8e8;
|
||||
color: #888;
|
||||
text-decoration: none;
|
||||
border-radius: 3px;
|
||||
-webkit-border-radius: 3px;
|
||||
-moz-border-radius: 3px;
|
||||
-moz-box-shadow: 0 2px 0 0 #e8e8e8;
|
||||
-webkit-box-shadow: 0 2px 0 0 #e8e8e8;
|
||||
box-shadow: 0 2px 0 0 #e8e8e8;
|
||||
padding: 6px 10px 4px 10px;
|
||||
color: #fff;
|
||||
background: #2f8ab9;
|
||||
border: none;
|
||||
-moz-box-shadow: 0 2px 0 0 #13648d;
|
||||
-webkit-box-shadow: 0 2px 0 0 #13648d;
|
||||
box-shadow: 0 2px 0 0 #13648d;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.ajax-file-upload:hover {
|
||||
background: #3396c9;
|
||||
-moz-box-shadow: 0 2px 0 0 #15719f;
|
||||
-webkit-box-shadow: 0 2px 0 0 #15719f;
|
||||
box-shadow: 0 2px 0 0 #15719f;
|
||||
}
|
||||
|
||||
.ajax-upload-dragdrop {
|
||||
border: 2px dotted #A5A5C7;
|
||||
width: 420px;
|
||||
color: #DADCE3;
|
||||
text-align: left;
|
||||
vertical-align: middle;
|
||||
padding: 10px 10px 0px 10px;
|
||||
}
|
||||
|
||||
.state-hover {
|
||||
border: 2px solid #A5A5C7;
|
||||
}
|
||||
|
||||
.ajax-file-upload-container {
|
||||
margin: 20px 0px 20px 0px;
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
|
||||
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui"%>
|
||||
|
||||
<portlet:defineObjects />
|
||||
|
||||
<script src="<%=request.getContextPath()%>/js/jquery.min.js"></script>
|
||||
<script src="<%=request.getContextPath()%>/js/jquery.uploadfile.min.js"></script>
|
||||
|
||||
|
||||
<%-- <portlet:actionURL var="uploadFileURL" name="uploadFiles" /> --%>
|
||||
<portlet:resourceURL var="uploadFileURL" id="uploadFiles" />
|
||||
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
$("#multipleupload").uploadFile({
|
||||
url:"<%=uploadFileURL.toString()%>",
|
||||
multiple : true,
|
||||
dragDrop : true,
|
||||
sequential:true,
|
||||
sequentialCount:1,
|
||||
maxFileCount:5,
|
||||
fileName : "myfile",
|
||||
onSuccess:function(files,data,xhr,pd) {
|
||||
console.log(data);
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<div id="multipleupload">Upload</div>
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue