Fóruns

Início » Liferay Portal » English » 3. Development

Visualização combinada Visão plana Exibição em árvore
Tópicos [ Anterior | Próximo ]
toggle
File Upload for Custom Portlet Karma Coma 24 de Agosto de 2011 06:40
RE: File Upload for Custom Portlet Manikandan S 25 de Agosto de 2011 00:16
RE: File Upload for Custom Portlet Karma Coma 25 de Agosto de 2011 00:44
RE: File Upload for Custom Portlet Manikandan S 25 de Agosto de 2011 01:29
RE: File Upload for Custom Portlet Yamini T 14 de Novembro de 2011 22:22
RE: File Upload for Custom Portlet Manikandan S 15 de Novembro de 2011 00:01
RE: File Upload for Custom Portlet Yamini T 15 de Novembro de 2011 22:20
RE: File Upload for Custom Portlet Manikandan S 16 de Novembro de 2011 01:03
RE: File Upload for Custom Portlet Yamini T 16 de Novembro de 2011 04:43
RE: File Upload for Custom Portlet Manikandan S 16 de Novembro de 2011 20:18
RE: File Upload for Custom Portlet Nguyen Le 26 de Maio de 2012 21:35
RE: File Upload for Custom Portlet Manikandan S 28 de Maio de 2012 01:43
RE: File Upload for Custom Portlet Nguyen Le 28 de Maio de 2012 01:51
RE: File Upload for Custom Portlet Nguyen Le 28 de Maio de 2012 01:54
RE: File Upload for Custom Portlet Manikandan S 28 de Maio de 2012 02:10
RE: File Upload for Custom Portlet Nguyen Le 28 de Maio de 2012 03:27
RE: File Upload for Custom Portlet Manikandan S 28 de Maio de 2012 03:30
RE: File Upload for Custom Portlet Nguyen Le 28 de Maio de 2012 03:46
RE: File Upload for Custom Portlet Manikandan S 28 de Maio de 2012 05:04
RE: File Upload for Custom Portlet Tejas patel 9 de Setembro de 2012 22:18
RE: File Upload for Custom Portlet Tejas patel 9 de Setembro de 2012 22:35
RE: File Upload for Custom Portlet Nguyen Le 10 de Setembro de 2012 02:40
RE: File Upload for Custom Portlet Nguyen Le 9 de Abril de 2013 01:15
RE: File Upload for Custom Portlet karthik reddy 3 de Junho de 2013 22:52
RE: File Upload for Custom Portlet natanael berlian 8 de Abril de 2013 19:47
RE: File Upload for Custom Portlet Manikandan S 8 de Abril de 2013 21:46
RE: File Upload for Custom Portlet natanael berlian 8 de Abril de 2013 22:40
RE: File Upload for Custom Portlet Manikandan S 8 de Abril de 2013 22:57
RE: File Upload for Custom Portlet natanael berlian 8 de Abril de 2013 23:01
RE: File Upload for Custom Portlet Manikandan S 8 de Abril de 2013 23:12
RE: File Upload for Custom Portlet Manikandan S 8 de Abril de 2013 23:28
RE: File Upload for Custom Portlet natanael berlian 8 de Abril de 2013 23:37
RE: File Upload for Custom Portlet Manikandan S 9 de Abril de 2013 00:02
RE: File Upload for Custom Portlet lun wang 5 de Agosto de 2013 05:31
RE: File Upload for Custom Portlet shrikanth k shrikanth 26 de Dezembro de 2013 02:19
RE: File Upload for Custom Portlet Ritresh Girdhar 27 de Dezembro de 2013 04:00
RE: File Upload for Custom Portlet Meera Prince 27 de Dezembro de 2013 07:44
Karma Coma
File Upload for Custom Portlet
24 de Agosto de 2011 06:40
Resposta

Karma Coma

Ranking: New Member

Mensagens: 12

Data de entrada: 18 de Fevereiro de 2011

Mensagens recentes

Hi all,

I tried many of the ways to upload a file in a custom portlet but every one failed..
This makes me mad :/

Could anyone show me some working code example?
Manikandan S
RE: File Upload for Custom Portlet
25 de Agosto de 2011 00:16
Resposta

Manikandan S

Ranking: Expert

Mensagens: 492

Data de entrada: 15 de Setembro de 2010

Mensagens recentes

Hi karma,

Here the source code for Upload file in custom portlet.
I think you will finish it off.
Anexos: UploadPortlet.java (3,0k), index.jsp (0,7k)
Karma Coma
RE: File Upload for Custom Portlet
25 de Agosto de 2011 00:44
Resposta

Karma Coma

Ranking: New Member

Mensagens: 12

Data de entrada: 18 de Fevereiro de 2011

Mensagens recentes

Thank you very much Mani! emoticon
Manikandan S
RE: File Upload for Custom Portlet
25 de Agosto de 2011 01:29
Resposta

Manikandan S

Ranking: Expert

Mensagens: 492

Data de entrada: 15 de Setembro de 2010

Mensagens recentes

You are welcomeemoticon
Yamini T
RE: File Upload for Custom Portlet
14 de Novembro de 2011 22:22
Resposta

Yamini T

Ranking: Junior Member

Mensagens: 32

Data de entrada: 26 de Julho de 2011

Mensagens recentes

Hi Mani,

I have done as you said in above examples, but I am getting NullPointer exception due to
I am getting length of bytes is null;
bytes = FileUtil.getBytes(file);
int length=bytes.length;

Thanks & Regards
Jhansi
Manikandan S
RE: File Upload for Custom Portlet
15 de Novembro de 2011 00:01
Resposta

Manikandan S

Ranking: Expert

Mensagens: 492

Data de entrada: 15 de Setembro de 2010

Mensagens recentes

Could you post you code here?
Yamini T
RE: File Upload for Custom Portlet
15 de Novembro de 2011 22:20
Resposta

Yamini T

Ranking: Junior Member

Mensagens: 32

Data de entrada: 26 de Julho de 2011

Mensagens recentes

Hi Mani,

below is the code at
view.jsp
-------------

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>

<portlet:defineObjects />

This is the <b>ImageUpload</b> portlet in View mode.
<form name="<portlet:namespace/>fm" method="post" enctype="multipart/form-data" action="<portlet:actionURL />" >
<table>
<tr>
<td>File : </td>

<td><input type="file" name="<portlet:namespace/>egfile" id="<portlet:namespace/>egfile" />
</td>
<td> <input type="hidden" name="hi" id="hi" value="Hi, HW r u?"/></td>
</tr>

<tr>
<td>&nbsp;</td>
<td><input type="submit" value="Upload"/></td>
</tr>
</table>
</form>

ImageUpload.java
--------------------------
public void processAction(ActionRequest actionRequest,
ActionResponse actionResponse) throws IOException, PortletException {

String realPath = getPortletContext().getRealPath("/");
byte[] bytes = null;
System.out.println("real path^^^^^^^^^^^^"+realPath);
UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);
String sourceFileName =uploadRequest.getFileName("egfile");
String f=ParamUtil.getString(uploadRequest,"egfile");
File file=uploadRequest.getFile(sourceFileName);
String str=ParamUtil.getString(uploadRequest,"hi");
System.out.println("fileNme"+sourceFileName+"+++++++++++++++++str"+str);
try {
bytes = FileUtil.getBytes(file);
} catch (IOException e2) {
e2.printStackTrace();
}
System.out.println("length of file"+bytes.length);

}
Manikandan S
RE: File Upload for Custom Portlet
16 de Novembro de 2011 01:03
Resposta

Manikandan S

Ranking: Expert

Mensagens: 492

Data de entrada: 15 de Setembro de 2010

Mensagens recentes

Remove
1File file=uploadRequest.getFile(sourceFileName);

Replace with this code,
1File file = uploadRequest.getFile("egfile");
Yamini T
RE: File Upload for Custom Portlet
16 de Novembro de 2011 04:43
Resposta

Yamini T

Ranking: Junior Member

Mensagens: 32

Data de entrada: 26 de Julho de 2011

Mensagens recentes

Hi Mani,

Thank you, I got it.

Thanks & Regards
Jhansi Rani P
Manikandan S
RE: File Upload for Custom Portlet
16 de Novembro de 2011 20:18
Resposta

Manikandan S

Ranking: Expert

Mensagens: 492

Data de entrada: 15 de Setembro de 2010

Mensagens recentes

You welcome emoticon
Nguyen Le
RE: File Upload for Custom Portlet
26 de Maio de 2012 21:35
Resposta

Nguyen Le

Ranking: New Member

Mensagens: 11

Data de entrada: 24 de Abril de 2012

Mensagens recentes

I had received image and text at server. If i save the image, I can't insert this text to database. If I insert text to database, I can't save the image. Please help me to do both.
Manikandan S
RE: File Upload for Custom Portlet
28 de Maio de 2012 01:43
Resposta

Manikandan S

Ranking: Expert

Mensagens: 492

Data de entrada: 15 de Setembro de 2010

Mensagens recentes

Could you share your code here?
Nguyen Le
RE: File Upload for Custom Portlet
28 de Maio de 2012 01:51
Resposta

Nguyen Le

Ranking: New Member

Mensagens: 11

Data de entrada: 24 de Abril de 2012

Mensagens recentes

Thanks 4 reply, I have uploaded a image and insert data from textfield to database.
Nguyen Le
RE: File Upload for Custom Portlet
28 de Maio de 2012 01:54
Resposta

Nguyen Le

Ranking: New Member

Mensagens: 11

Data de entrada: 24 de Abril de 2012

Mensagens recentes

Can you help me passing parameter between 2 portlet???
Manikandan S
RE: File Upload for Custom Portlet
28 de Maio de 2012 02:10
Resposta

Manikandan S

Ranking: Expert

Mensagens: 492

Data de entrada: 15 de Setembro de 2010

Mensagens recentes

Unless seeing your code I cant do anything. Could you share your code here?
Nguyen Le
RE: File Upload for Custom Portlet
28 de Maio de 2012 03:27
Resposta

Nguyen Le

Ranking: New Member

Mensagens: 11

Data de entrada: 24 de Abril de 2012

Mensagens recentes

OK, I will send my code into your email. Please tell me your email. emoticon
Manikandan S
RE: File Upload for Custom Portlet
28 de Maio de 2012 03:30
Resposta

Manikandan S

Ranking: Expert

Mensagens: 492

Data de entrada: 15 de Setembro de 2010

Mensagens recentes

sachinmani07@gmail.com
Nguyen Le
RE: File Upload for Custom Portlet
28 de Maio de 2012 03:46
Resposta

Nguyen Le

Ranking: New Member

Mensagens: 11

Data de entrada: 24 de Abril de 2012

Mensagens recentes

Mani kandan:
sachinmani07@gmail.com



I was sent, check your email please.
Manikandan S
RE: File Upload for Custom Portlet
28 de Maio de 2012 05:04
Resposta

Manikandan S

Ranking: Expert

Mensagens: 492

Data de entrada: 15 de Setembro de 2010

Mensagens recentes

I uploaded working file upload war file..

I added getLiferayDatabaseConnection() function in your code(which means database connectivity using context.xml)
Anexos: FileUpload-portlet-6.0.1.war (26,6k)
Tejas patel
RE: File Upload for Custom Portlet
9 de Setembro de 2012 22:18
Resposta

Tejas patel

Ranking: Junior Member

Mensagens: 71

Data de entrada: 23 de Janeiro de 2012

Mensagens recentes

HI nguyen le,
I have same problem like your .
can you please give solution here how could you solve your problem.
Thanks in advance.
If any one else have solution then please share it here .
the problem is i want to add image as well as some text in database from user.
it does not work with enctype="multipart/form-data".
if i do not add this statment the text added and image not added,
if i add this statment the image added and the text does not get in process action class.
but my requirement is to get both thing from user and store in database.

Thanks and regards,
Tejas patel.
Tejas patel
RE: File Upload for Custom Portlet
9 de Setembro de 2012 22:35
Resposta

Tejas patel

Ranking: Junior Member

Mensagens: 71

Data de entrada: 23 de Janeiro de 2012

Mensagens recentes

I got the answer by the following method.
File file=uploadRequest.getFile("fileName to get from jsp");
String name=uploadRequest.getParameter("name to get form jsp");

Thanks,
Tejas patel.
Nguyen Le
RE: File Upload for Custom Portlet
10 de Setembro de 2012 02:40
Resposta

Nguyen Le

Ranking: New Member

Mensagens: 11

Data de entrada: 24 de Abril de 2012

Mensagens recentes

Tejas Patel:
I got the answer by the following method.
File file=uploadRequest.getFile("fileName to get from jsp");
String name=uploadRequest.getParameter("name to get form jsp");

Thanks,
Tejas patel.



Hi Tejas Patel, I have been uploaded file(image) and text(TextField) by using ParamUtil class. Do you want see it, email to me.
natanael berlian
RE: File Upload for Custom Portlet
8 de Abril de 2013 19:47
Resposta

natanael berlian

Ranking: New Member

Mensagens: 14

Data de entrada: 25 de Março de 2013

Mensagens recentes

hello manni, I've used your code to upload. portlet is success to run but I don't know, my file is success or not to upload. because there is no file in path folder i choose
can you help me?
this is my code
 1package com.git.upload;
 2
 3import java.io.FileInputStream;
 4import java.io.FileNotFoundException;
 5import java.io.FileOutputStream;
 6import java.io.IOException;
 7import java.util.Vector;
 8import java.io.File;
 9
10
11import javax.portlet.ActionRequest;
12import javax.portlet.ActionResponse;
13import javax.portlet.GenericPortlet;
14import javax.portlet.PortletContext;
15import javax.portlet.PortletException;
16import javax.portlet.PortletRequestDispatcher;
17import javax.portlet.RenderRequest;
18import javax.portlet.RenderResponse;
19
20import com.liferay.portal.kernel.upload.UploadPortletRequest;
21import com.liferay.portal.kernel.util.FileUtil;
22import com.liferay.portal.util.PortalUtil;
23
24
25public class uploadFile extends GenericPortlet{
26
27    protected String viewJSP;
28    protected String process;
29    protected Vector<?> v=null;
30    protected String realPath = null;
31   
32    public void init() throws PortletException{
33        viewJSP = getInitParameter("view-jsp");
34    }
35    public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException
36    {
37        realPath = getPortletContext().getRealPath("/");
38        System.out.println(realPath);
39       
40        byte[] bytes = null;
41        PortletContext portletContext = request.getPortletSession().getPortletContext();
42        try {
43            UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(request);
44            String sourcefileName = uploadRequest.getFileName("fileName");
45            File file = uploadRequest.getFile("fileName");
46            try {
47                bytes = FileUtil.getBytes(file);
48               
49            } catch (IOException e2) {
50                e2.printStackTrace();// TODO: handle exception
51            }
52            File newFile= null;
53            if((bytes != null) && (bytes.length > 0))
54            {
55                try {
56                    System.out.println(sourcefileName);
57                   
58                    newFile = new File(realPath+"html/uploads/"+sourcefileName);
59                    FileInputStream fileInputStream = new FileInputStream(file);
60                    FileOutputStream fileOutputStream = new FileOutputStream(newFile);
61                    fileInputStream.read(bytes);
62                   
63                    String value = new String(bytes);
64                    System.out.println(value);
65                   
66                    fileOutputStream.write(bytes,0,bytes.length);
67                    fileOutputStream.close();
68                    fileInputStream.close();
69                } catch (FileNotFoundException e) {
70                    System.out.println("file not found");
71                    e.printStackTrace();// TODO: handle exception
72                }
73            }
74        } catch (IOException e1) {
75            System.out.println("Error reading the file");
76            e1.printStackTrace();// TODO: handle exception
77        }
78    }
79   
80    public void render(RenderRequest request, RenderResponse response) throws PortletException, IOException
81    {
82        doView(request, response);
83    }
84    public void doView(RenderRequest request, RenderResponse response) throws IOException
85    {
86        //private static Log _log = LogFactoryUtil.getLog(upload)
87        String path=viewJSP;
88        PortletRequestDispatcher portletRequestDispatcher = getPortletContext().getRequestDispatcher(path);
89        if(portletRequestDispatcher ==null){
90            
91        }
92    }
93}


thanks
Manikandan S
RE: File Upload for Custom Portlet
8 de Abril de 2013 21:46
Resposta

Manikandan S

Ranking: Expert

Mensagens: 492

Data de entrada: 15 de Setembro de 2010

Mensagens recentes

Remove this code and check,

String value = new String(bytes);
System.out.println(value);
natanael berlian
RE: File Upload for Custom Portlet
8 de Abril de 2013 22:40
Resposta

natanael berlian

Ranking: New Member

Mensagens: 14

Data de entrada: 25 de Março de 2013

Mensagens recentes

Mani kandan:
Remove this code and check,

String value = new String(bytes);
System.out.println(value);



that is still not happening. this is my full source code and WAR.
Anexos: uploadFile.java (2,8k), uppp-portlet.war (29,6k)
Manikandan S
RE: File Upload for Custom Portlet
8 de Abril de 2013 22:57
Resposta

Manikandan S

Ranking: Expert

Mensagens: 492

Data de entrada: 15 de Setembro de 2010

Mensagens recentes

Are you getting "sourcefileName" in the portlet class?

Just print sourcefileName in the portlet class
natanael berlian
RE: File Upload for Custom Portlet
8 de Abril de 2013 23:01
Resposta

natanael berlian

Ranking: New Member

Mensagens: 14

Data de entrada: 25 de Março de 2013

Mensagens recentes

Mani kandan:
Are you getting "sourcefileName" in the portlet class?

Just print sourcefileName in the portlet class



sourcefileName just string from class UploadPortletRequest

I'm sorry if I'm wrong, I'm new in Liferay..
Manikandan S
RE: File Upload for Custom Portlet
8 de Abril de 2013 23:12
Resposta

Manikandan S

Ranking: Expert

Mensagens: 492

Data de entrada: 15 de Setembro de 2010

Mensagens recentes

Just give,
System.out.println(sourcefileName);
after
String sourcefileName = uploadRequest.getFileName("fileName");
and see wt is coming in the print
Manikandan S
RE: File Upload for Custom Portlet
8 de Abril de 2013 23:28
Resposta

Manikandan S

Ranking: Expert

Mensagens: 492

Data de entrada: 15 de Setembro de 2010

Mensagens recentes

Try with this file
Anexos: view.jsp (1,1k)
natanael berlian
RE: File Upload for Custom Portlet
8 de Abril de 2013 23:37
Resposta

natanael berlian

Ranking: New Member

Mensagens: 14

Data de entrada: 25 de Março de 2013

Mensagens recentes

Mani kandan:
Try with this file



that's still not happening. I think this problem because my uploadportlet.java is not running. Is that true? because when I sysout the beginning of uploadportlet.java, there is no printed in console.
Manikandan S
RE: File Upload for Custom Portlet
9 de Abril de 2013 00:02
Resposta

Manikandan S

Ranking: Expert

Mensagens: 492

Data de entrada: 15 de Setembro de 2010

Mensagens recentes

Try this,

http://lauraliparulo.altervista.org/liferay-upload-file-portlet-working-example-with-upload-progress-bar/
Nguyen Le
RE: File Upload for Custom Portlet
9 de Abril de 2013 01:15
Resposta

Nguyen Le

Ranking: New Member

Mensagens: 11

Data de entrada: 24 de Abril de 2012

Mensagens recentes

Tejas Patel:
HI nguyen le,
I have same problem like your .
can you please give solution here how could you solve your problem.
Thanks in advance.
If any one else have solution then please share it here .
the problem is i want to add image as well as some text in database from user.
it does not work with enctype="multipart/form-data".
if i do not add this statment the text added and image not added,
if i add this statment the image added and the text does not get in process action class.
but my requirement is to get both thing from user and store in database.

Thanks and regards,
Tejas patel.


Sorry, I late.

I will show my source code, you can references. If you have any problems, Please email to me(nguyenlx90@hotmail.com)

view.jsp
<input type="file" name="hotelImage" />
<input name="txtHotel" type="text" value="" size=60>

processAction:
public void processAction(ActionRequest req, ActionResponse res) throws PortletException {
try {
UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(req);
File imageFile = uploadRequest.getFile("hotelImage");
String imageFileName = imageFile.getName();

String txtHotel = ParamUtil.getString(uploadRequest,"txtHotel");

...
// Save image to file system/insert to DB, insert text into DB is successed
} catch (Exception e1) {
e1.printStackTrace();
}
}
karthik reddy
RE: File Upload for Custom Portlet
3 de Junho de 2013 22:52
Resposta

karthik reddy

Ranking: Junior Member

Mensagens: 50

Data de entrada: 8 de Abril de 2013

Mensagens recentes

Hi,
I have 2 components in view.jsp. I want to send data in 2 components to JAVA file, save file on web server and insert data received from textfileld into database. Already i completed to store in server.Now my requirement is to store that image in database also with some primary key and also before storing into database when i choose that image it should display in the same page.Please give reply how to achieve this.


Thanks & Regards
M.Karthik
lun wang
RE: File Upload for Custom Portlet
5 de Agosto de 2013 05:31
Resposta

lun wang

Ranking: New Member

Mensagens: 1

Data de entrada: 31 de Julho de 2013

Mensagens recentes

Hi,Mani now I use liferay MVCPortlet to upload file,
UploadPortletRequest upRequest = PortalUtil.getUploadPortletRequest(request);
File file = request.getFiles("uploadFile");
if (file != null) {
byte[] bytes = FileUtil.getBytes(file);
if ((bytes != null) && (bytes.length > 0)) {

String sourceFileName = file.getName();
String mimeType = MimeTypesUtil.getContentType(file);
ServiceContext serviceContext = ServiceContextFactory.getInstance(DLFileEntry.class.getName(), request);
FileEntry fileEntry = DLAppLocalServiceUtil.addFileEntry(userId, repositoryId,FileConstants.MEETING_RECORD_FOLDER,
sourceFileName, mimeType, null, null, null,file, serviceContext);
}
when i ipload a txt,it fill failed ,i debug it found that no file in D:\liferay-portal-6.1.10-ee-ga1\tomcat-7.0.25\temp\ do not find uploadFile_0019436.txt
but when i load a doc or excl ,it will be ok!
i found when UploadPortletRequest upRequest = PortalUtil.getUploadPortletRequest(request); The upload file will copy to D:\liferay-portal-6.1.10-ee-ga1\tomcat-7.0.25\temp\ ,but when i upload a txt,it will not copy. Do you have any suggestion or example code.
i'm a chinese ,so my English is poor,i'm looking forword your advices, thank you!!
shrikanth k shrikanth
RE: File Upload for Custom Portlet
26 de Dezembro de 2013 02:19
Resposta

shrikanth k shrikanth

Ranking: Regular Member

Mensagens: 111

Data de entrada: 10 de Dezembro de 2013

Mensagens recentes

hello sir......

i want to upload image in MYSQL database.so plz help me if u have code plz send me iam using MVCportlet
Ritresh Girdhar
RE: File Upload for Custom Portlet
27 de Dezembro de 2013 04:00
Resposta

Ritresh Girdhar

Ranking: Junior Member

Mensagens: 67

Data de entrada: 15 de Julho de 2011

Mensagens recentes

Dear try This:

public void uploadCase(ActionRequest actionRequest,
ActionResponse actionRresponse) throws PortletException,
IOException {
String realPath = "C:\\Liferay 6.1.3\\liferay-portal-tomcat-6.1.2-ce-ga3-20130816114619181\\liferay-portal-6.1.2-ce-ga3\\data\\CandidatesExcel\\";
logger.info("RealPath" + realPath + " UploadFolder :");
try {
UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);
System.out.println("Size: "+uploadRequest.getSize("candidates"));
if (uploadRequest.getSize("candidates")==0) {
SessionErrors.add(actionRequest, "error");
}
String candidates []= uploadRequest.getFileNames("candidates");
File files[] = uploadRequest.getFiles("candidates");
logger.info("Nome file:" + uploadRequest.getFileName("candidates"));
ArrayList<File> newFiles=new ArrayList<>();
for(int j=0;j<files.length;j++)
{

File newFile = new File(realPath + candidates);
System.out.println("newFile.getPath() "+newFile.getPath());
logger.info("New file name: " + newFile.getName());
logger.info("New file path: " + newFile.getPath());
InputStream in = new BufferedInputStream(uploadRequest.getFilesAsStream("candidates"));
FileInputStream fis = new FileInputStream(files);
FileOutputStream fos = new FileOutputStream(newFile);
byte[] bytes_ = FileUtil.getBytes(in);
int i = fis.read(bytes_);
while (i != -1) {
fos.write(bytes_, 0, i);
i = fis.read(bytes_);
}
fis.close();
fos.close();
newFiles.add(newFile);
SessionMessages.add(actionRequest, "success");
}

} catch (FileNotFoundException e) {
System.out.println("File Not Found.");
e.printStackTrace();
SessionMessages.add(actionRequest, "error");
} catch (NullPointerException e) {
System.out.println("File Not Found");
e.printStackTrace();
SessionMessages.add(actionRequest, "error");
}catch (IOException e1) {
System.out.println("Error Reading The File.");
SessionMessages.add(actionRequest, "error");
e1.printStackTrace();
}
}


JSP:


<portlet:actionURL var="uploadFileURL">
<portlet:param name="myActions" value="uploadMultipleFile"></portlet:param>
</portlet:actionURL>

<script type="text/javascript">
jQuery(function(){ // wait for document to load
jQuery('#uploadFile').MultiFile({
STRING: {
remove: '<img src="http://www.fyneworks.com/@/bin.gif" height="16" width="16" alt="x"/>'
}
});
});


function uploadNewFile()
{
jQuery('#fileTags').find('input[type="file"]').each(
function() {
var id = jQuery(this).attr('id');
jQuery(this).attr('name',id);
});
document.multipleUpload.action='<portlet:actionURL><portlet:param name="myActions" value="uploadMultipleFile"/></portlet:actionURL>';
document.multipleUpload.submit();
}
</script>




<form enctype="multipart/form-data" method="post" name="multipleUpload">
<table id="fileTags">
<tbody>
<tr><td>Upload File</td>
<td><input class="multi" id="uploadFile" name="uploadFile" type="file" />
</td>
<td></td>
</tr>
</tbody></table>
<input onclick="uploadNewFile()" type="button" value="Upload" />
</form>
Meera Prince
RE: File Upload for Custom Portlet
27 de Dezembro de 2013 07:44
Resposta

Meera Prince

Ranking: Liferay Legend

Mensagens: 1110

Data de entrada: 8 de Fevereiro de 2011

Mensagens recentes

HI

The following is example portlet to upload image using BLOB data type in service builder
I have done this to 6.2 portal and same you can do for other version it will work as for my guess..

http://www.liferaysavvy.com/2013/12/using-blob-data-type-in-liferay-service.html


Regards,

Meera Prince

http://www.liferaysavvy.com