Using jquery to upload files

Hi
I have uploaded files before but not using jquery but now am trying to use jquery so that my files uploads without page refreshing.
This is my Jquery code. and below is the html code. Can any one help me with the jquery code so that I can get the data to the php script that process
the variables.
JQUERY:
<script type="text/javascript">
$(document).ready(function() {
   $("#photoform").submit(function() {
                            var phototitle = $("phototitle").val();
                            var photogenre = $("photogenre").val();
                            var photodesc = $("photodesc").val();
                            var photofield = $("photofield").val();
    $.post("Uploadfix.php", { phototitle: phototitle,
     photogenre: photogenre, photodesc: photodesc, photofield: photofield}, function(data) {
     $("#allresult").html(data);
   return false;
//-->
</script>
PHP CODE:
$phototitle=addslashes(strip_tags($_POST['phototitle']));
$photogenre=addslashes(strip_tags($_POST['photogenre']));
$photodesc=addslashes(strip_tags($_POST['photodesc']));
$photo=$_FILES["photofield"]["name"];
$type=$_FILES["photofield"]["type"];
$size=$_FILES["photofield"]["size"];
$temp_name=$_FILES["photofield"]["tmp_name"];
$error=$_FILES["photofield"]["error"];
echo "$phototitle";
echo "<br/>";
echo "$photo";
echo "<br/>";
echo "$type";
echo "<br/>";
html:
<form id="photoform" method="post" enctype="multipart/form-data" action=''>
//id variables:
</form>
How can I read in the file from jquery to the php sucessfully. NO SUCESS YET!
Thanks.

Hi Gramps
Thank for the reply. If I use form action like the code below it works but I can not do validation.
<script type="text/javascript" >
/* $(document).ready(function() {
            $("#photoform").submit(function(e)         {
            $("#allresult").html('');
            $("#allresult").html('<img src="PHOTOTEST/loader.gif" alt="Uploading...."/>');
            $("#photoform").ajaxForm({
                        target: '#allresult'
        }).submit();
</script>
HTML:
<form id='photoform' enctype='multipart/form-data' method='post' action='process.php'>
</form>
PHP:
$example=$_POST['INPUT'];
if($example>5)
echo "input greater than 5 sorry.";
else
//process data
The problem is this is echoed in a new page which is process.php. Instead of on a div on the page that is submitting the form. I know this is
because of the form action. how can I make the validation appear on a div on same page?
cheers.

Similar Messages

  • I use FireFTP to upload files. This past week the profilesuddenly stopped connecting. Ideas?

    I manage two Websites and use FireFTP to upload files for both of them due to FireFTP's ease of use. I've never had a problem connecting before last week. The files on the host (my computer) show, but there is no response when I click on the "Connect" button. These were already established profiles and have worked before, and I have made no changes. I've tried to make the connection fairly frequently over the past week (this has been going on for a full week now), and tried a few minutes ago to confirm there was still a problem. There is. Did I have only a limited time to use FireFTP? If so, I don't recall being advised of that when I downloaded and installed it. I'd gladly pay a nominal fee just to not have to learn another FTP app, although there are many free FTP apps available on the Internet. Further, Firefox itself is not working -- I can not see any Webpages using Firefox, although in using IE or Chrome, the Webpages I seek come up. In fact, I had to find your Website and fill out this support ticket via IE. What is going on with Firefox and FireFTP? Thx.

    If Firefox won't connect, as well as FireFTP not connecting, the most common reason would be a firewall block after the update. That and other reasons are discussed in the following support articles:
    * [[Fix problems connecting to websites after updating Firefox]]
    * [[Firefox can't load websites but other browsers can]]
    Anything there help?

  • How to use mutex in uploading file

    Hi, All
    I used myfaces upload component. It works all right for me. Because I had a lot of process for the uploaded file and it might take long. So I'd like page to return (tell users that the file is in process) after successfully upload the file and let another "thread" or something else continue to work on the file.
    Is this possible to do? and how? Any code will be very welcome.
    Thx

    Just spawn a new Thread? Read on the Thread and Runnable API's.
    Thread API: http://java.sun.com/javase/6/docs/api/java/lang/Thread.html
    Runnable API: http://java.sun.com/javase/6/docs/api/java/lang/Runnable.html
    Cuncurrency tutorial: http://java.sun.com/docs/books/tutorial/essential/concurrency/index.html

  • How to use jquery.hotkeys.js in ADF application

    Hello all,
    I am developing an ADF application where i am trying to use jquery.hotkeys.js file. I have created a folder js inside ViewController\Web Content\js and i have added jquery.hotkeys.js file inside that folder.
    Now i have created a jspx page and inside that i have 3 input text and 1 submit button now I am trying to use keyboard shortcuts say ALT+F8 to clear the form fields. Here is my full jspx form
    <?xml version='1.0' encoding='windows-1252'?>
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
    <jsp:directive.page contentType="text/html;charset=windows-1252"/>
    <f:view>
    <af:document id="d1">
    <af:form id="f1">
    <af:inputText label="First Name" id="it1" value="#{MyBean2.firstName}">
    <af:clientListener method="clearAll" type="keyDown"/>
    </af:inputText>
    <af:inputText label="Last Name" id="it2" value="#{MyBean2.lastName}">
    <af:clientListener method="clearAll" type="keyDown"/>
    </af:inputText>
    <af:inputText label="EmailID" id="it3" value="#{MyBean2.emailId}">
    <af:clientListener method="clearAll" type="keyDown"/>
    </af:inputText>
    <af:commandButton text="Submit" id="cb1"
    action="#{MyBean2.callSubmit}"
    binding="#{MyBean2.cb1}">
    <af:clientListener method="clearAll" type="keyDown"/>
    </af:commandButton>
    </af:form>
    <f:facet name="metaContainer">
    <af:resource type="javascript" source="/js/jquery.hotkeys.js"/>
    <af:resource type="javascript">
    function clearAll() {
    $("*").bind('keydown', 'Alt+F8', function (evt) {
    clearForm();
    evt.stopPropagation();
    return false;
    function clearForm() {
    alert('3');
    curElm = document.activeElement;
    var frm = $(curElm).closest('form');
    var frmname = ($(frm).attr('name'));
    document.forms[frmname].reset();
    document.getElementById('frmname::content').reset();
    document.getElementById('f1::content').reset();
    $("input:visible:enabled:first").focus();
    </af:resource>
    </f:facet>
    </af:document>
    </f:view>
    </jsp:root>
    But that is not working. Can anyone help?
    Thanks

    My requirement is the form should get cleared on pressing ALT + F8.
    Here is my updated jspx page:-
    <?xml version='1.0' encoding='windows-1252'?>
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
    <jsp:directive.page contentType="text/html;charset=windows-1252"/>
    <f:view>
    <af:document id="d1">
    <af:form id="f1">
    <af:inputText label="First Name" id="it1" value="#{MyBean2.firstName}">
    </af:inputText>
    <af:inputText label="Last Name" id="it2" value="#{MyBean2.lastName}">
    </af:inputText>
    <af:inputText label="EmailID" id="it3" value="#{MyBean2.emailId}">
    <af:clientListener method="clearAll" type="keyDown"/>
    </af:inputText>
    <af:commandButton text="Submit" id="cb1"
    action="#{MyBean2.callSubmit}"
    binding="#{MyBean2.cb1}">
    <af:clientListener method="clearAll" type="keyDown"/>
    </af:commandButton>
    </af:form>
    <f:facet name="metaContainer">
    <af:resource type="javascript" source="/js/jquery.hotkeys.js"/>
    <af:resource type="javascript" source="/js/jquery-1.4.4.min.js"/>
    <af:resource type="javascript">
    function clearAll() {
    jQuery('*').bind('keydown', 'Alt+F8', function (evt) {
    clearForm();
    evt.stopPropagation();
    return false;
    function clearForm() {
    curElm = document.activeElement;
    var frm = $(curElm).closest('form');
    var frmname = ($(frm).attr('name'));
    alert(frmname);
    document.forms[frmname].reset();
    $("input:visible:enabled:first").focus();
    </af:resource>
    </f:facet>
    </af:document>
    </f:view>
    </jsp:root>
    But still I am not able to get the desired functionality. Am i missing something here?
    Thanks

  • How can we limit uploading file size in portal.

    we have a feature where customers can upload there files, we use portals for uploading files, form which has the file type is posted to a stored procedure and which in turns calls the wwv_things.saveitem.
    we need to restrict a file size and file type for the uploading files, I can restrict the file type with javasript but wanted to find out if oracle portals has any way to restrict the uploading file size,
    thanks and regards,
    Sunil.

    Currently, this is not available. You could have a query that has all RKF as a starting point to achieve this. If you think this would be good to have by default, please log a development request on the OSS Messaging System.

  • Charset in uploaded file

    Hi all,
    I'm developing a internationalized web application. Should work all over the world, all languages.
    One function is to allow the user to upload his CSV with contacts, exported from Outlook or GMail for example.
    Everything seems to work fine if clients have charset Windows-1252 or ISO-8859-1. But when a UTF16 file comes, I need to specify it in my code in order to display the file contents correctly:
    byte[] fileContents = new byte[(int) getUploadFile().getSize()];          
    int bytesRead = getUploadFile().getStream().read(fileContents);
    this._fileContents = new String(fileContents); // for windows-1252 or iso-8859-1
    //this._fileContents = new String(fileContents, "UTF16"); // for utf16But how can I know what charset is used in the uploaded file? Or can I do the file reading in another way so I don't need to know?
    Any help appreciated!

    The only reason it works without the specification of a character set is that you are probably testing this on an English Windows system - where the default system codepage is 1252. If you switch the system codepage to be Japanese, for instance, your 8859-1 and 1252 encoded data would fail.
    So, you do need to specify the character set when you read the file - I don't know of any 'magic' that would work without it.
    Since you won't know in advance, the only workaround I can think of would be to do charset detection - using something like the CharsetDetector in ICU4J:
    http://www.icu-project.org/apiref/icu4j/com/ibm/icu/text/CharsetDetector.html
    Bear in mind that this will not be perfect, especially for files with little text in them.
    Good luck!

  • Problem by uploading files via gui_upload with large files

    I´m using gui_upload to upload files to the application server. When I´m trying to trasfer files bigger than 150MB I get the exception dp_out_of_memory.

    Hi Patrick,
    I'm always getting a 'TVS_NEW_PAGE_ALLOC_FAILED'-dump. There current memory usage is inside, also a hint, which parameters have to be changed.
    I think, you are in a similar situation. Have a look, if system parameter abap/heap_area_dia is your limit. There is also a parameter abap/heaplimit, which is limit for one workprocess. Probably this triggers your dump (but all based on my experience with unsuccessful new page allocation).
    Maybe your 'no roll' dump is more linked to parameters ztta/roll_area - ask a basis expert / have a look in OSS.
    Regards,
    Christian

  • Prevent overwrite of upload file

    I'm using jspsmart to upload file to the server.
    How can I prevent overwrite of file ?
    for example,
    User A have a file call "abc.txt" in the server. Now, another user B upload a file call "abc.txt".
    The problem is User A and User B upload the file with the same filename in the same directory.
    Any method can give User B a warning signal to prevent overwrite of the file.
    Thank you !

    To prevent an overwrite of a file, first check to see if file exists BEFORE uploading the file.
    For example.
    String filename = "abc.txt";
    File f = new File(filename);
    if(f.exists()) // file already exists ->give error
    else // file not exists->upload file

  • File uploads using jQuery with jquery.fileupload.js fails in Firefox over SSL

    Please see the link below where I originally posted the question.
    http://stackoverflow.com/questions/27792614/file-uploads-using-jquery-with-jquery-fileupload-js-fails-in-firefox-over-ssl

    Thanks. In my estimation that is exactly the issue. But that doesn't help with a resolution.
    The actual file size: 945,991 bytes
    If Firefox is miscalculating the length (in Safari/Chrome 945991 and 946241 in Firefox), then Firefox is reporting erroneously and should be raised as a bug in Firefox, would you agree?

  • Unable to upload Files to child site collection using REST

    Dear All,
    I referred this article http://www.shillier.com/archive/2013/03/26/uploading-files-in-sharepoint-2013-using-csom-and-rest.aspx for uploading documents to SP Document Library and it works fine for any document library under the root site collection(
    for example "http://<server name>/Shared Documents" but when i upload the same document to one of the sub site collection created using Managed Path( the site collection path is "http://<server name>/files/Case" and the library
    name is "records") it fails and i get below error:
    The security validation for this page is invalid. Click Back in your
    Web browser, refresh the page, and try your operation again, Error Code -2130575251 Microsoft.SharePoint.SPException"
    Any help suggestion to resolve this? I've almost tried everything to resolve this issue but no luck.. appreciate any help
    for this..
    Regards,
    Vishal

    Hi,
    According to your post, my understanding is that you had an issue uploading files to subsite using REST.
    I had made a simple code demo below, it will upload a file to Document Library after you make your selection with the File control.
    <script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    function uploadFile(){
    //alert(2);
    if (document.getElementById("file").files.length === 0) {
    alert('No file was selected');
    return;
    var parts = document.getElementById("file").value.split("\\");
    var filename = parts[parts.length - 1];
    var file = document.getElementById("file").files[0];
    uploadFileSync("http://YourSite", "Documents", filename, file);
    //Upload file synchronously
    function uploadFileSync(spWebUrl , library, filename, file)
    //alert(3);
    var reader = new FileReader();
    reader.onloadend = function(evt)
    if (evt.target.readyState == FileReader.DONE)
    var buffer = evt.target.result;
    var completeUrl = spWebUrl
    + "/_api/web/lists/getByTitle('"+ library +"')"
    + "/RootFolder/Files/add(url='"+ filename +"',overwrite='true')?"
    + "@TargetLibrary='"+library+"'&@TargetFileName='"+ filename +"'";
    $.ajax({
    url: completeUrl,
    type: "POST",
    data: buffer,
    async: false,
    processData: false,
    headers: {
    "accept": "application/json;odata=verbose",
    "X-RequestDigest": $("#__REQUESTDIGEST").val(),
    "content-length": buffer.byteLength
    complete: function (data) {
    //uploaded pic url
    console.log(data.responseJSON.d.ServerRelativeUrl);
    error: function (err) {
    alert('failed');
    reader.readAsArrayBuffer(file);
    </script>
    <input type="file" id='file' onchange="uploadFile()"/>
    Thanks,
    Jason
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected].
    Jason Guo
    TechNet Community Support

  • CF9 - Upload file via jQuery.post("document.cfm",serialize())

    Hello, everyone.
    I'm working on a form that will add/edit task details.  One of the requirements is the ability to upload files into the database.
    If a task is being EDITED, the upload is no problem; I'm using a hidden iframe to handle the upload, and the task will have a task ID that the file will be associated with.
    However, if a task is being ADDED, there is no existing task ID, so the file needs to be uploaded with the rest of the form.  Unfortunately, jQuery .post() using the .serialize() attribute for the form breaks file uploads, because the form isn't multipart/form-data, at that point.
    Does anyone have any suggestions on how to allow a file upload if the form is being submit via jQuery.post("document.cfm",serialize(formobject))?
    Thank you,
    ^_^

    Hi, Martin.
    Thanks for the reply.
    1. The form is encoded as multipart/form-data AND the function that submits the data is also enforcing enctype and encoding as multipart/form-data.
    2. Plugins are not up to me, unfortunately.  Can't download them, much less install them.  The dev and production environments are super-tight.
    I think I will need to find a way to have a hidden iframe upload the file(s) first, keep them in the VFS until the task is submit via AJaX, get the task ID and pass it to another script that will insert the files into the database, then delete them from the VFS.
    Way more than I wanted to do, but I'm thinking it's my only option.
    ^_^

  • Maximum size of upload file using Cross Domain Library

    Hi All 
    I need to know what is the maximum size of file that I can upload using Cross Domain Library from my Provider hosted app. I know that in msdn it is written that usign REST call we can upload upto 2GB but I have doubts if it is true with Cross domain library
    REST Calls. Please suggest.
     spExecutor.executeAsync(
                                   url: fileCollectionEndpoint,
                                   method: "POST",
                                   contentType: "application/json;odata=verbose",
                                   body: filedata,
                                   binaryStringRequestBody: true,
                                   headers: { "X-RequestDigest": $("#__REQUESTDIGEST").val(), "accept": "application/json;odata=verbose" ........
    And Can I pass ArrayBuffer directly or I need to pass only binary string ?
    Thanks in Advance 

    Hi,
    According to your post, my understanding is that you want to know the Maximum size of upload file using Cross Domain Library.
    Per my knowledge, you can upload files up to 2 GB with the REST API. 
    You can refer to:
    How to: Upload a file by using the REST API and jQuery
    In addition, you can pass ArrayBuffer directly. Please refer to:
    FileCollection methods
    Thanks,
    Linda Li                
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Linda Li
    TechNet Community Support

  • Using ABAP Webdynpr How to Upload File and download file in SAP R/3

    Hi SAP GURUS ,
                             I wanted to save employee profile from ESS to SAP so i am creating ESS Application .
    For that I go with BDS Approach and create test program for this  I got success while uploading file in my folder
    which i have created with the help of class and content repository . but when i Using ABAP Webdynpro , i got error FM "BDS_BUSINESSDOCUMENT_CREATEF"  message " error_kpro " .
                           Also I wanted to use KM for storage of Documents and wanted to retrive with help of ABAP Webdynpro .
                           So pls tell me / mailed me the process , approach and if you have examples .
        Thanks in Advance ,
         Vishwassap at gmail

    Hi Vishwas,
    Check out the thread [Efficient way of saving documents uploaded|Re: Efficient way of saving documents uploaded by users; and check the blog by Raja Thangamani.
    Also check the thread [Export Images through Function Modules   |Export Images through Function Modules;.
    Hope it helps you.

  • Hi, I am using HP11 and iPlanet web server. When trying to upload files over HTTP using FORM ENCTYPE="multipart/form-data" that are bigger than a few Kilobytes i get a 408 error. (client timeout).

    Hi, I am using HP11 and iPlanet web server. When trying to upload files over HTTP using FORM ENCTYPE="multipart/form-data" that are bigger than a few Kilobytes i get a 408 error. (client timeout). It is as if the server has decided that the client has timed out during the file upload. The default setting is 30 seconds for AcceptTimeout in the magnus.conf file. This should be ample to get the file across, even increasing this to 2 minutes just produces the same error after 2 minutes. Any help appreciated. Apologies if this is not the correct forum for this, I couldn't see one for iPlanet and Web, many thanks, Kieran.

    Hi,
    You didnt mention which version of IWS. follow these steps.
    (1)Goto Web Server Administration Server, select the server you want to manage.
    (2)Select Preference >> Perfomance Tuning.
    (3)set HTTP Persistent Connection Timeout to your choice (eg 180 sec for three minutes)
    (4) Apply changes and restart the server.
    *Setting the timeout to a lower value, however, may    prevent the transfer of large files as timeout does not refer to the time that the connection has been idle. For example, if you are using a 2400 baud modem, and the request timeout is set to 180 seconds, then the maximum file size that can be transferred before   the connection is closed is 432000 bits (2400 multiplied by 180)
    Regards
    T.Raghulan
    [email protected]

  • We can use JSR-168 JPS portlet upload file,

    We can use JSR-168 JPS portlet upload file,
    here is the source for you referrence:
    upload file can use JSR168 portlet,
    1,CustomizablePortlet.java File
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.ResourceBundle;
    import javax.portlet.*;
    import oracle.webdb.utils.SimpleStringBuffer;
    public class CustomizablePortlet extends GenericPortlet {
    private static final String TITLE_KEY = "title";
    protected static final String OK_ACTION = "ok_action";
    protected static final String APPLY_ACTION = "apply_action";
    protected static final PortletMode PREVIEW_MODE = new PortletMode("preview");
    protected static final PortletMode EDIT_DEFAULTS_MODE = new PortletMode("EDIT_DEFAULTS");
    protected static final PortletMode ABOUT_MODE = new PortletMode("ABOUT");
    public CustomizablePortlet() {
    public String getTitle(RenderRequest request) {
    return request.getPreferences().getValue("title", getPortletConfig().getResourceBundle(request.getLocale()).getString("javax.portlet.title"));
    public void doEdit(RenderRequest request, RenderResponse response) throws PortletException, IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.print("<FORM ACTION=\"");
    out.print(getEditFormSubmitURL(request, response));
    out.println("\" METHOD=\"POST\">");
    out.println("<TABLE BORDER=\"0\">");
    out.println("<TR>");
    out.println("<TD WIDTH=\"20%\">");
    out.println("<P CLASS=\"portlet-form-field\" ALIGN=\"RIGHT\">Title:");
    out.println("</TD>");
    out.println("<TD WIDTH=\"80%\">");
    out.print("<INPUT CLASS=\"portlet-form-input-field\" TYPE=\"TEXT\" NAME=\"");
    out.print("title");
    out.print("\" VALUE=\"");
    out.print(getTitle(request));
    out.println("\" SIZE=\"20\">");
    out.println("</TD>");
    out.println("</TR>");
    out.println("<TR>");
    out.println("<TD COLSPAN=\"2\" ALIGN=\"CENTER\">");
    out.print("<INPUT CLASS=\"portlet-form-button\" TYPE=\"SUBMIT\" NAME=\"");
    out.print("ok_action");
    out.print("\" VALUE=\"OK\">");
    out.print("<INPUT CLASS=\"portlet-form-button\" TYPE=\"SUBMIT\" NAME=\"");
    out.print("apply_action");
    out.print("\" VALUE=\"Apply\">");
    out.println("</TD>");
    out.println("</TR>");
    out.println("</TABLE>");
    out.println("</FORM>");
    protected String getEditFormSubmitURL(RenderRequest request, RenderResponse response) {
    return response.createActionURL().toString();
    public void doHelp(RenderRequest request, RenderResponse response) throws PortletException, IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.print("Help for <i><b>");
    out.print(getTitle(request));
    out.println("</b></i>.");
    public void doAbout(RenderRequest request, RenderResponse response) throws PortletException, IOException {
    String aboutHTML = (new SimpleStringBuffer(30)).append("/about_").append(getPortletName()).append(".html").toString();
    PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(aboutHTML);
    response.setContentType("text/html");
    if(rd != null) {
    rd.include(request, response);
    } else {
    PrintWriter out = response.getWriter();
    out.print("<p class=\"portlet-font\">This is the about page for ");
    out.print(getTitle(request));
    out.print(".</p><p class=\"portlet-font\">");
    out.print("To customize the contents of this page, create a file named '");
    out.print(aboutHTML.substring(1));
    out.print("' in the Portlet web application's root directory containing HTML ");
    out.print("to appear here. ");
    out.print("Alternatively, override the <code>CustomizablePortlet</code> ");
    out.println("class's <code>doAbout()</code> method.</p>");
    public void doDispatch(RenderRequest request, RenderResponse response) throws PortletException, IOException {
    WindowState state = request.getWindowState();
    if(!state.equals(WindowState.MINIMIZED)) {
    PortletMode mode = request.getPortletMode();
    if(mode.equals(PREVIEW_MODE))
    doView(request, response);
    else
    if(mode.equals(EDIT_DEFAULTS_MODE))
    doEdit(request, response);
    else
    if(mode.equals(ABOUT_MODE))
    doAbout(request, response);
    else
    super.doDispatch(request, response);
    } else {
    super.doDispatch(request, response);
    public void processAction(ActionRequest request, ActionResponse actionResponse) throws PortletException, IOException {
    String newTitle = request.getParameter("title");
    PortletPreferences prefs = request.getPreferences();
    prefs.setValue("title", newTitle);
    prefs.store();
    if(request.getParameter("ok_action") != null) {
    actionResponse.setPortletMode(PortletMode.VIEW);
    actionResponse.setWindowState(WindowState.NORMAL);
    2,FileUploadPortlet.java file
    import java.io.*;
    import javax.activation.DataHandler;
    import javax.mail.MessagingException;
    import javax.mail.internet.MimeBodyPart;
    import javax.portlet.*;
    import oracle.portal.portlet.sample.CustomizablePortlet;
    public class FileUploadPortlet extends CustomizablePortlet
    private static final String FILE_PARAM = "file";
    private static final String SUBMIT_PARAM = "submit";
    private static final String DEFAULT_CHARSET = "ISO-8859-1";
    private static final String uploadRoot = "";
    public FileUploadPortlet()
    public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.print("<form action=\"");
    out.print(response.createActionURL().toString());
    out.println("\" enctype=\"multipart/form-data\" method=\"post\">");
    out.println("<center><table border=\"0\">");
    out.println("<tr>");
    out.print("<td class=\"portlet-form-field\" align=\"right\">");
    out.print("Please browse to an HTML file:");
    out.println("</td>");
    out.print("<td>");
    out.print("<input class=\"portlet-form-input-field\" type=\"file\" name=\"");
    out.print("file");
    out.print("\">");
    out.println("</td>");
    out.println("</tr>");
    out.println("<tr>");
    out.println("<td colspan=\"2\" align=\"center\">");
    out.print("<input type=\"submit\" class=\"portlet-form-button\" name=\"");
    out.print("submit");
    out.print("\" value=\"Display\">");
    out.println("</td>");
    out.println("</tr>");
    out.println("</table>");
    out.println("</form>");
    String lastFile = request.getPreferences().getValue("file", null);
    if(lastFile != null) {
    out.println("<hr width=\"100%\"><br>");
    out.print(lastFile);
    public void processAction(ActionRequest request, ActionResponse actionResponse) throws PortletException, IOException {
    FormDataParser parsedRequest = new FormDataParser(request);
    MimeBodyPart mbp = parsedRequest.getMimeBodyPart("file");
    if(mbp == null)
    super.processAction(request, actionResponse);
    else
    try {
    String fileName= mbp.getFileName();
    int splash = fileName.lastIndexOf("\\");
    if(splash != -1)
    fileName = fileName.substring(splash +1, fileName.length()).trim();
    String contentType = mbp.getContentType();
    String charSet = getCharsetFromContentType(contentType);
    int sepIndex = contentType.indexOf(';');
    if(sepIndex != -1)
    contentType = contentType.substring(0, sepIndex).trim();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    mbp.getDataHandler().writeTo(bos);
    bos.close();
    String content = new String(bos.toByteArray(), charSet);
    FileOutputStream fos = new FileOutputStream(fileName);
    fos.write(bos.toByteArray());
    fos.close();
    PortletPreferences prefs = request.getPreferences();
    prefs.setValue("file", fileName + "upload ok");
    prefs.store();
    catch(MessagingException me) {
    throw new PortletException(me);
    public static String getCharsetFromContentType(String contentType) {
    int lastPos;
    if((lastPos = contentType.indexOf(';')) == -1)
    return "ISO-8859-1";
    lastPos++;
    String lowerContentType = contentType.toLowerCase();
    int nextPos;
    do {
    nextPos = lowerContentType.indexOf(';', lastPos);
    String param;
    if(nextPos == -1)
    param = lowerContentType.substring(lastPos).trim();
    else
    param = lowerContentType.substring(lastPos, nextPos).trim();
    if(param.startsWith("charset=") && param.length() > 8)
    return param.substring(8);
    lastPos = nextPos + 1;
    } while(nextPos != -1);
    return "ISO-8859-1";
    3,FormDataParser.java file
    import java.io.*;
    import java.util.*;
    import javax.activation.DataSource;
    import javax.mail.MessagingException;
    import javax.mail.internet.MimeBodyPart;
    import javax.mail.internet.MimeMultipart;
    import javax.portlet.ActionRequest;
    import javax.portlet.PortletException;
    public class FormDataParser {
    private static final String MULTIPART_PREFIX = "multipart/";
    private static final String MULTIPART_FORM_DATA = "multipart/form-data";
    private static final String PLAIN_TEXT = "text/plain";
    private ActionRequest mWrappedRequest;
    private Map mParams;
    private Map mBodyParts;
    private boolean mIsInitialized;
    private boolean mHasMultipart;
    public FormDataParser(ActionRequest request) {
    mWrappedRequest = request;
    public String getParameter(String name) throws PortletException {
    String value = mWrappedRequest.getParameter(name);
    if(value != null)
    return value;
    initParameters();
    if(!mHasMultipart)
    return null;
    List paramList = (List)mParams.get(name);
    if(paramList != null)
    return (String)paramList.get(0);
    else
    return null;
    public String[] getParameterValues(String name) throws PortletException {
    String values[] = mWrappedRequest.getParameterValues(name);
    if(!mHasMultipart)
    return values;
    initParameters();
    List valueList = (List)mParams.get(name);
    if(valueList == null)
    return values;
    int size = valueList.size();
    if(values != null) {
    List newValueList = new ArrayList(values.length + size);
    newValueList.addAll(Arrays.asList(values));
    newValueList.addAll(valueList);
    valueList = newValueList;
    values = new String[size];
    valueList.toArray(values);
    return values;
    public MimeBodyPart getMimeBodyPart(String name) throws PortletException {
    initParameters();
    if(!mHasMultipart) {
    return null;
    } else {
    List parts = (List)mBodyParts.get(name);
    return parts != null ? (MimeBodyPart)parts.get(0) : null;
    public MimeBodyPart[] getMimeBodyParts(String name) throws PortletException {
    initParameters();
    if(!mHasMultipart)
    return null;
    List parts = (List)mBodyParts.get(name);
    if(parts == null) {
    return null;
    } else {
    MimeBodyPart mimeBodyParts[] = new MimeBodyPart[parts.size()];
    parts.toArray(mimeBodyParts);
    return mimeBodyParts;
    private void initParameters() throws PortletException {
    if(mIsInitialized)
    return;
    String contentType = mWrappedRequest.getContentType();
    if(contentType == null) {
    mIsInitialized = true;
    return;
    int sepIndex = contentType.indexOf(';');
    if(sepIndex != -1)
    contentType = contentType.substring(0, sepIndex).trim();
    if(contentType.equalsIgnoreCase("multipart/form-data")) {
    mParams = new HashMap(20);
    mBodyParts = new HashMap(20);
    DataSource ds = new DataSource() {
    public InputStream getInputStream() throws IOException {
    return mWrappedRequest.getPortletInputStream();
    public OutputStream getOutputStream() throws IOException {
    throw new IOException("OutputStream not available");
    public String getContentType() {
    return mWrappedRequest.getContentType();
    public String getName() {
    return getClass().getName();
    try {
    MimeMultipart multipartMessage = new MimeMultipart(ds);
    parseMultiPart(multipartMessage, null);
    catch(MessagingException me) {
    throw new PortletException(me);
    catch(IOException ioe) {
    throw new PortletException(ioe);
    mHasMultipart = true;
    mIsInitialized = true;
    private void parseMultiPart(MimeMultipart multipartMessage, String parentFieldName) throws MessagingException, IOException {
    int partCount = multipartMessage.getCount();
    for(int i = 0; i < partCount; i++) {
    javax.mail.BodyPart part = multipartMessage.getBodyPart(i);
    if(part instanceof MimeBodyPart) {
    MimeBodyPart mimePart = (MimeBodyPart)part;
    String disps[] = mimePart.getHeader("Content-Disposition");
    if(disps != null && disps.length != 0) {
    String disp = disps[0];
    String lcDisp = disp.toLowerCase();
    int nameStart;
    int nameEnd;
    if((nameStart = lcDisp.indexOf("name=\"")) != -1 && (nameEnd = lcDisp.indexOf("\"", nameStart + 6)) != -1)
    parentFieldName = disp.substring(nameStart + 6, nameEnd);
    if(parentFieldName != null)
    if(mimePart.getContentType().toLowerCase().startsWith("multipart/")) {
    Object content = mimePart.getContent();
    if(content instanceof MimeMultipart)
    parseMultiPart((MimeMultipart)content, parentFieldName);
    } else
    if((nameStart = lcDisp.indexOf("filename=\"")) != -1 && (nameEnd = lcDisp.indexOf("\"", nameStart + 10)) != -1) {
    List values = (List)mBodyParts.get(parentFieldName);
    if(values == null) {
    values = new ArrayList(1);
    mBodyParts.put(parentFieldName, values);
    values.add(mimePart);
    } else
    if(mimePart.getContentType().toLowerCase().startsWith("text/plain")) {
    Object content = mimePart.getContent();
    if(content instanceof String) {
    List values = (List)mParams.get(parentFieldName);
    if(values == null) {
    values = new ArrayList(1);
    mParams.put(parentFieldName, values);
    values.add((String)content);
    4.web.xml file
    <?xml version = '1.0' encoding = 'ISO-8859-1'?>
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
    <display-name>hanhuiwen OracleSamplePortlets</display-name>
    <description>hanhuiwen Oracle Sample Portlet Application</description>
    <servlet>
    <servlet-name>portletdeploy</servlet-name>
    <servlet-class>oracle.webdb.wsrp.server.deploy.PortletDeployServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet>
    <servlet-name>portletjaxrpc</servlet-name>
    <servlet-class>com.sun.xml.rpc.server.http.JAXRPCServlet</servlet-class>
    <init-param>
    <param-name>configuration.file</param-name>
    <param-value>/WEB-INF/WSRPService_Config.properties</param-value>
    </init-param>
    </servlet>
    <servlet>
    <servlet-name>portletresource</servlet-name>
    <servlet-class>oracle.webdb.wsrp.server.ResourceServlet</servlet-class>
    </servlet>
    <servlet>
    <servlet-name>ChartServlet</servlet-name>
    <display-name>Chart Servlet</display-name>
    <description>Demo image-generating servlet</description>
    <servlet-class>oracle.portal.portlet.sample.chart.ChartServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet>
    <servlet-name>uix</servlet-name>
    <servlet-class>oracle.cabo.servlet.UIXServlet</servlet-class>
    <init-param>
    <param-name>oracle.cabo.servlet.pageBroker</param-name>
    <param-value>oracle.cabo.servlet.xml.UIXPageBroker</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>ChartServlet</servlet-name>
    <url-pattern>/chart*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>portletjaxrpc</servlet-name>
    <url-pattern>/portlets*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>portletresource</servlet-name>
    <url-pattern>/portletresource*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>uix</servlet-name>
    <url-pattern>*.uix</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>uix</servlet-name>
    <url-pattern>/uix/*</url-pattern>
    </servlet-mapping>
    <session-config>
    <session-timeout>60</session-timeout>
    </session-config>
    <welcome-file-list>
    <welcome-file>index.uix</welcome-file>
    </welcome-file-list>
    <!--
    LogLevel controls the amount of information logged. There are 7 log levels:
    0 - logging disabled
    1 - configuration
    2 - severe error
    3 - warning
    4 - throwing exception
    5 - performance
    6 - information
    7 - debug
    The oracle.portal.log.Logger interface defines methods that map to these 7
    log levels. However, there are also 2 methods that do not map to log
    levels. These methods are included for backwards compatibility and data
    logged using these methods will always be logged regardless of the log level.
    -->
    <env-entry>
    <env-entry-name>oracle/portal/log/logLevel</env-entry-name>
    <env-entry-type>java.lang.Integer</env-entry-type>
    <env-entry-value>7</env-entry-value>
    </env-entry>
    </web-app>
    5.portlet.xml
    <?xml version = '1.0' encoding = 'UTF-8'?>
    <portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd" version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">
    <portlet>
    <description xml:lang="en">A portlet that demonstrates the file upload features of the Java Portlet Specification.</description>
    <portlet-name>FileUpload</portlet-name>
    <portlet-class>FileUploadPortlet</portlet-class>
    <expiration-cache>0</expiration-cache>
    <supports>
    <mime-type>text/html</mime-type>
    <portlet-mode>help</portlet-mode>
    <portlet-mode>about</portlet-mode>
    <portlet-mode>edit_defaults</portlet-mode>
    </supports>
    <supported-locale>en</supported-locale>
    <portlet-info>
    <title>File Upload Portlet</title>
    <short-title>File Upload</short-title>
    <keywords>File,Upload, Portlet</keywords>
    </portlet-info>
    </portlet>
    <custom-portlet-mode>
    <description xml:lang="en">This mode should be used by the portlet to display information on the portlet's purpose, origin, version, etc.</description>
    <portlet-mode>about</portlet-mode>
    </custom-portlet-mode>
    <custom-portlet-mode>
    <description xml:lang="en">This mode signifies that the portlet should render a screen to set the default values for the modifiable preferences that are typically changed in the EDIT screen. Calling this mode requires that the user must have administrator rights.</description>
    <portlet-mode>edit_defaults</portlet-mode>
    </custom-portlet-mode>
    <custom-portlet-mode>
    <description xml:lang="en">This mode should be used by the portlet to render output without the need of having back-end connections or user specific data available.</description>
    <portlet-mode>preview</portlet-mode>
    </custom-portlet-mode>
    <user-attribute>
    <name>user.name.given</name>
    </user-attribute>
    <user-attribute>
    <name>user.name.family</name>
    </user-attribute>
    <user-attribute>
    <name>user.name.middle</name>
    </user-attribute>
    <user-attribute>
    <name>user.name.nickname</name>
    </user-attribute>
    <user-attribute>
    <name>user.bdate</name>
    </user-attribute>
    <user-attribute>
    <name>user.business-info.online.email</name>
    </user-attribute>
    </portlet-app>

    Hello i had exactly the same error, but not with file upload.
    I'm sure you have in your application lib directory to jars which aren't compatible to each other.
    And the problem occured between my myfaces and tomahawk jars .
    See this page:
    http://wiki.apache.org/myfaces/CompatibilityMatrix
    It tells you which myfaces and tomahawk jars you can use together.
    Hope it can help.
    bye

Maybe you are looking for

  • I am trying to download itunes and keep getting an error message cannot access network location %appdata%

    I am trying to download itunes to windows 7 and keep getting the error message "cannot access network location $APPDATA%\." I have contacted an Apple advisor and was not able to resolve the problem. What to do?

  • Service master mass update

    Hi All, We have issue in which while creating Service master, wrong unit of measure was used. Now to correct this, we need to do mass update of these service masters created. Is there any way in to do this. Any program that SAP has which would solve

  • How to launch bootcamp quicker?

    So, as I use Windows on my Mac pretty often, it gets annoying to always go to System Preferences - Startup Disk - Select BOOTCAMP, and only then reboot in the partition. Is there a shortcut to this? Maybe some kind of utility that would allow to boot

  • Background Processing/ F9

    Hi All, Hi have created a program that selects data from a particular table and load it a new session of ms excel program. It automatically opens ms excel through ole2_objects and populates the rows one by one. Yet there is a new requirement. The use

  • Is there a student discount on macs

    Im looking into buying a mac laptop and I was wondering if Apple offers any sort of discount for college students?