How to Upload file

45 views
Skip to first unread message

rdjava30

unread,
Jun 29, 2018, 11:51:48 AM6/29/18
to Hippo Community
Hi Community I try to upload file , but in my action class I am getting null pointer exception.

Below is part of my code

@Override
public void doAction(HstRequest request, HstResponse response) throws HstComponentException {

System.out.println("In Action");
try {

Part part = request.getPart("file");
InputStream fis = part.getInputStream(); // getting null pointer exception as part is null
int content;
while ((content = fis.read()) != -1) {
// convert to char and display it
System.out.print((char) content + "-" + content);
}

}

Woonsan Ko

unread,
Jun 29, 2018, 1:05:46 PM6/29/18
to hippo-c...@googlegroups.com
Did you submit the form with POST method and enctype="multiplart/form-data" [1] and <@hst.actionURL/>?



--
Hippo Community Group: The place for all discussions and announcements about Hippo CMS (and HST, repository etc. etc.)
 
To post to this group, send email to hippo-community@googlegroups.com
RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-community+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/hippo-community.
For more options, visit https://groups.google.com/d/optout.



--
Message has been deleted

Raman Singh

unread,
Jul 3, 2018, 7:25:59 AM7/3/18
to hippo-c...@googlegroups.com
Yes.. I included

On Fri, Jun 29, 2018, 1:05 PM Woonsan Ko <woons...@bloomreach.com> wrote:
Did you submit the form with POST method and enctype="multiplart/form-data" [1] and <@hst.actionURL/>?


On Fri, Jun 29, 2018 at 11:51 AM, rdjava30 <rdja...@gmail.com> wrote:
Hi Community I try to upload file , but in my action class I am getting null pointer exception.

Below is part of my code

@Override
public void doAction(HstRequest request, HstResponse response) throws HstComponentException {

System.out.println("In Action");
try {

Part part = request.getPart("file");
InputStream fis = part.getInputStream(); // getting null pointer exception as part is null
int content;
while ((content = fis.read()) != -1) {
// convert to char and display it
System.out.print((char) content + "-" + content);
}

}

--
Hippo Community Group: The place for all discussions and announcements about Hippo CMS (and HST, repository etc. etc.)
 
To post to this group, send email to hippo-c...@googlegroups.com

RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-communi...@googlegroups.com.

--
Hippo Community Group: The place for all discussions and announcements about Hippo CMS (and HST, repository etc. etc.)
 
To post to this group, send email to hippo-c...@googlegroups.com

RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-communi...@googlegroups.com.

Marijan Milicevic

unread,
Jul 3, 2018, 7:59:09 AM7/3/18
to hippo-c...@googlegroups.com
On Fri, Jun 29, 2018 at 7:30 PM, rdjava30 <rdja...@gmail.com> wrote:
Yes I did


On Friday, June 29, 2018 at 1:05:46 PM UTC-4, woonsan.ko wrote:
Did you submit the form with POST method and enctype="multiplart/form-data" [1] and <@hst.actionURL/>?



On Fri, Jun 29, 2018 at 11:51 AM, rdjava30 <rdja...@gmail.com> wrote:
Hi Community I try to upload file , but in my action class I am getting null pointer exception.

Below is part of my code






you cannot use Parts API, without configuring tomcat first,
you need to change context.xml and add allowCasualMultipartParsing="true" parameter (https://tomcat.apache.org/tomcat-8.0-doc/config/context.html ) and you also might need to change connector so it accepts more than 2MB default upload size ( maxPostSize)

Much easier is just to use file upload lib:


    <dependency>
      <groupId>commons-fileupload</groupId>
      <artifactId>commons-fileupload</artifactId>
      <version>1.3.3</version>
    </dependency>

API is almost the same..
cheers
marijan



@Override
public void doAction(HstRequest request, HstResponse response) throws HstComponentException {

System.out.println("In Action");
try {

Part part = request.getPart("file");
InputStream fis = part.getInputStream(); // getting null pointer exception as part is null
int content;
while ((content = fis.read()) != -1) {
// convert to char and display it
System.out.print((char) content + "-" + content);
}

}

--
Hippo Community Group: The place for all discussions and announcements about Hippo CMS (and HST, repository etc. etc.)
 
To post to this group, send email to hippo-c...@googlegroups.com

RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-communi...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages