Code for uploading larger image or any file object

I have this code which is working file for files <500 KB
* To change this template, choose Tools | Templates
* and open the template in the editor.
package controller;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Properties;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.http.Part;
* @author Chinmay
public class ProfileImage_Update extends HttpServlet {
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        Part p = request.getPart("file");
        InputStream in = (InputStream) p.getInputStream();
        byte[] b = new byte[in.available()];
        in.read(b, 0, b.length);
        Connection connection = null;
        PreparedStatement stmt = null;
        HttpSession session = request.getSession();
        String username = (String) session.getAttribute("username");
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Properties properties = new Properties();
            connection = DriverManager.getConnection("jdbc:odbc:sn", properties);
            stmt = connection.prepareStatement("UPDATE Photos SET Photo = ? WHERE username = ?");
            stmt.setBytes(1, b);
            stmt.setString(2, username);
            int rows = stmt.executeUpdate();
            if (rows > 0) {
                RequestDispatcher view = request.getRequestDispatcher("Home.jsp");
                view.forward(request, response);
        } catch (ClassNotFoundException ex) {
            out.println(ex);
        } catch (SQLException ex) {
            out.println(ex);
        } finally {
            in.close();
            try {
                connection.close();
                stmt.close();
            } catch (SQLException ex) {
                ex.printStackTrace();
            out.close();
    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
     * Returns a short description of the servlet.
     * @return a String containing servlet description
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}But when i give file which is greater than 500 KB it shows the following error. What can be the problem???
java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]The text, ntext, or image pointer value conflicts with the column name specified. i have tried with compression logic but still i cannot get. what can be the problem in this case???
I am using SQL server 2005.

Maybe this site will have some useful info.

Similar Messages

  • How can we add a control on our .jsp webpage for uploading several image fi

    How can we add a control on our .jsp webpage for uploading several image files as done in gmail attachment, Where a Remove button also appears if we wanna remove the particular attachment.

    The SCOM Management Server is in Domain A.  I've tried it already and it has failed.  
    So just to clarify the method I used was to go to Administration>Security>User Roles.  Then New User Role>Read-Only Operator.  In the Create User Role Wizard I then gave the User Role a name, Clicked "Add" under User Role Members.
     Then the Select Users or Groups window pops up and I changed the Locations from Domain A to Domain B and searched for the user, which it's able to find, then clicked "OK" to add it to the User Role members which it does just fine.  On
    the next page which is Group Scope I checked the one group I want this account to have access to and then click next.  This brings me to Dashboards and Views where I click the radio button for "Only the dashboards and views selected in each tab are
    approved" and chose the folder of dashboards I want this account to access and then click next.  This brings me to the Summary and I click "Create".  At this point it thinks for a moment then closes out the wizard but the new Read-Only
    Operator does not appear.  I then look in Event Viewer and see the Event I pasted above.
    Am I doing something wrong here?  Any guidance on how to get around this issue would be much appreciated.
    Thanks,
    Jake

  • Reg: Upload an image from IBM File Net into SAP ZTABLE .

    HI,
    I have a requiremnt to Upload an image from IBM File into SAP ZTABLE .
    or
    can anyone give me an idea on
    How to Upload an image from any image software into SAP ZTABLE .
    Thnaks,
    Arjun
    Edited by: Arjun on Jan 22, 2010 2:24 PM

    hI,
    I've found the solution!!
    My code was wrong, the correct way is:
    DATA:  image type XSTRING,
                imagelength type i.
    DATA: it_img TYPE w3mimetabtype.
    CALL FUNCTION 'SSFC_BASE64_DECODE'
       EXPORTING
         b64data = output-CONVERT_FROM_URL_RESULT
       IMPORTING
         bindata = image
       EXCEPTIONS
         OTHERS  = 8.
    CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
       EXPORTING
         buffer                = image
         "APPEND_TO_TABLE       = ' '
       IMPORTING
         OUTPUT_LENGTH         = imagelength
       tables
         binary_tab            = it_img.

  • ROLLOVER for a large image to appear

    I am redoing my previous website. In that site, I had movie
    clip within a movie clip. This new site will not work using that
    procedure.
    The new website situation:
    My website is setup with small images, two in a row and two
    columns of four small images 60pixels x 68pixels. Those are on the
    right side and also on the left side (with different set of small
    images). In the center, which is now blank, will be for the large
    image to appear.
    This is want I am aiming for: Upon MOUSE ROLLOVER on a small
    image, the large image is to appear in the center, not on top of
    the small image.
    The Large image is to come about whenever the mouse is rolled
    upon a small image.
    I am still learning Flash. Hope someone can assist me with
    the above mentioned situation.
    [email protected]

    Good point Dzedward,
    I think however that since she has only a few images, she
    could just turn her small images into buttons, create rollover
    states, and import the larger photo images into the middle space
    where she would like them.
    Should you like to try this Alice, it is extremely easy.
    turn each of your small images into buttons, double click on
    the new button, noticing now that there are four squares by the
    timeline titled "up" "over" "down", and "hit"
    Click once on the "over" box, then go to
    File....Import.....Import to Stage... scroll through your directory
    until you find the large image you desire. Import it.
    Now you can place it wherever you like, once that is
    finished, go up into the control panel between comand and window,
    then scroll down to "test movie"
    I hope this helps, and works for you.
    Should you have alot of images, this method would definately
    make your file size large, and hence upload much slower.
    Copel

  • Code for reading particular  fields from the file placed in application

    hi,
    code for reading particular  fields from the file placed in application server in to the internal table.

    Hi,
    Use the GUI_UPLOAD FM to upload the File into ur Internal Table.
    DATA : FILE_TABLE TYPE FILE_TABLE OCCURS 0,
             fwa TYPE FILE_TABLE,
             FILENAME TYPE STRING,
             RC TYPE I.
    CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
      EXPORTING
        WINDOW_TITLE            = 'Open File'
       DEFAULT_EXTENSION       =
       DEFAULT_FILENAME        =
       FILE_FILTER             =
       INITIAL_DIRECTORY       =
       MULTISELECTION          =
       WITH_ENCODING           =
      CHANGING
        FILE_TABLE              = FILE_TABLE
        RC                      = RC
       USER_ACTION             =
       FILE_ENCODING           =
      EXCEPTIONS
        FILE_OPEN_DIALOG_FAILED = 1
        CNTL_ERROR              = 2
        ERROR_NO_GUI            = 3
        NOT_SUPPORTED_BY_GUI    = 4
        others                  = 5
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    READ TABLE FILE_TABLE INDEX 1 into fwa.
    FILENAME = fwa-FILENAME.
        CALL FUNCTION 'GUI_UPLOAD'
             EXPORTING
                  filename                = filename
                  FILETYPE                = 'DAT'
           IMPORTING
                FILELENGTH              =
             TABLES
                  data_tab                = itab
             EXCEPTIONS
                  file_open_error         = 1
                  file_read_error         = 2
                  no_batch                = 3
                  gui_refuse_filetransfer = 4
                  invalid_type            = 5
                  OTHERS                  = 6 .
        IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
    Regards,
    Balakumar.G
    Reward Points if helpful.

  • How to upload a image or flash file as blob object in a table.

    How to upload a image or flash file as blob object in a table.
    What are all the possible ways we can do it.

    Searching the forum (or google) would be my first choice, as this question pops up every now and then.
    Next without knowledge of your environment (jdev version and technology stack) it's hard to give a profound answer.
    All I can say is that it's possible.
    Timo

  • T-codes for uploading material prices and domestic prices?

    t-codes for uploading material prices and domestic prices?
    regards

    Use Transaction VK11 and VK12 based on Condition type for price .
    Please reward if useful.

  • Applescript for selecting an image in PDF file.

    Hi All,
    I'm looking for a apple or java script for selecting an image in PDF file. Can anyone help?

    Selecting an image? For what purpose?

  • How to upload an image to EBS file server (Not store in database) with OAF?

    Dear all,
    I can upload an image into database with blob type. But I want to know how to upload an image to EBS file server. I try to search the forum but I cannot find the solution I want.
    Anybody can reallize it? Please give me some advice or idea?
    Thanks.
    Kenny

    Kenny,
    Framework doesn't provide the option of storing the images as files. You can write a javascript to open a popup and provide a standard HTML file upload component which will save the file on specified location.
    --Shiv                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Function for uploading  multiple images, say 5000 , of any type?

    Hi,
    I want to upload multiple images which are stored anywhere, be it a local system or a server, to the SAP database just by clicking a single button. The method should be able to pick all the images and check their file types and upload it.
    My concerns are that:
    1. How to specify the path where the images are stored?
    2. How to check the extension of the different files. it is possible that the folder may contain some other file types? So how to distinguish between them?
    3. How to deal when the folders may contain some subfolders?
    4. How to display the uploaded images back to the user?
    Regards
    Amit Kumar Singh

    I would guess its because all of the file fields all have the
    same name. Try naming them dynamically: micro1, micro2, micro3,
    etc.
    A few minor comments about the code
    - Afaik, setting the VALUE has no effect for input fields
    when type="file"
    - FILE is deprecated. Use CFFILE.ServerFile instead
    - You don't need # signs here <cfset numberoffields =
    #cookie.micro#>
    Not tested

  • Pseudo code for DOM parsing a local XMl file

    HI all,
    1)     Can any body please provide me the JAVA pseudo code for parsing xml document from local mcahine and create another xml document in another location in loca machine with small transofrmations ? (JAVA mapping using DOM parsing tehnique using an xml file in loca machine using NWDS).
    2) Provide me with the links that can help me out to work with
    JAVA mapping using DOM
    Thanks,
    Ram.

    Hi,
    Have a Search in SDN with Keywords JAVA Mapping, & will get lot of stuff
    Implermenting JAVA Mapping in PI
    Implementing a Java Mapping in SAP PI
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/10dd67dd-a42b-2a10-2785-91c40ee56c0b
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/400ee77e-f9d6-2a10-2b8c-99281a4dcf6b
    Regards
    Seshagiri

  • Can I create an email form that includes a field for uploading and image?

    I'd like to create an email form in Muse that allows people to submit the usual text but also allows them to browse for and upload an image that would be emailed (attached or inline) to me along with the text.
    Does anyone know if there's a way to do that directly in Muse?
    Thanks.

    Which form?
    Many of the forms are created with LiveCycle ES so it might be possible to edit the form with Acrobat X Professional. If you have the data in an SQL database, you could possibly create a data connection and import the data into the form and save a copy of the completed form. You can also use the Acrobat JavaScript 'importTextData' to import a row of data from a tab delimited data file.
    You might want to talk to other Real Estate professionals to see how they are going do this. If you have a property management program, that program might have an update to perform this task.

  • In the Online Shop Layouts: Individual Product - Large, is there a tag for the Large Image value?

    I need a tag for the URL to the large image in order to use the Facebook Feed dialog (share).
    See example at https://aesgatorshack.worldsecuresystems.com/gator-shack/ladies/ladies-aes-pep-rally-repli ca-jersey.
    When you click the "Share on Facebook" link, it doesn't use a photo.  I can specify a photo to use; however, I need the URL to the image.
    Here's the Facebook code as is:
    <a href="#" class="social_button social_blue" onclick="window.open('https://www.facebook.com/dialog/feed?link={tag_itemurl_withhost}&amp;app_id=271818569626492&amp;redirect_uri={tag_itemurl_withhost}& amp;name={tag_name}&amp;display=popup','Sharing My AES Gator Shack Finds','width=640,height=320');">Share on Facebook</a>
    I can add the picture= parameter, but I need the URL to the image.

    There is no way to get the value of the large image tag like you can for image fields in webapps. In webapps, if you created a field called "image" then you can output the whole image markup with {tag_image} or just the URL to the image with {tag_image_value}.
    This isn't possible with the large product image.  I recently had to implement a Pin It Button on an eCommerce site on BC and had to use javascript to update the link that triggers the Pin It button with the URL of the image.  Here's what I suggest.  Instead of doing the whole code in the "onclick" attribute, you should use some jQuery and some data-* attributes and set the whole link up with that instead of inline javascript on the anchor element.
    Here's a fiddle that should work for you. It requires jQuery to be loaded before you include this script on your page and requires you to update your markup to the markup shown in my example.  Should be an easy cut and paste:
    http://jsfiddle.net/thetrickster/KQmdd/

  • I am getting this message as I try to upload raw images from my file folders to my PSE

    I am getting this message as I try to upload raw image files from my file/folders into PSE what do I do to get PSE to accept the raw files?
    "Nothing was imported. The file(s) or folder(s) selected to import did not contain any supported file types"  What do I do.  Just to let you guys know I am able to upload all JPEG files that are already in my files into PSE but not the raw photos.  Obviously I want to keep them raw in order to have more control over the outcome of the picture.

    The  camera I am using is the Canon Rebel T3I, the PSE version is elements 9, and I don't know what version of raw converter I may or may not be using.  Where do I find the version of raw converter?

  • I need Expert Decomposition of classes in Source Code for my reaserch purpose. Any body can help me in this regard?

    <blockquote>Locked by Moderator as a duplicate/re-post.
    Please continue the discussion in this thread: [tiki-view_forum_thread.php?comments_parentId=698286&forumId=1]
    Thanks - c</blockquote>
    == Issue
    ==
    I have another kind of problem with Firefox
    == Description
    ==
    I need Expert Decomposition of classes in Source Code of Firefox for my research purpose. Any body can help me in this regard?
    == This happened
    ==
    Not sure how often
    == Firefox version
    ==
    3.0.19
    == Operating system
    ==
    Windows XP
    == User Agent
    ==
    Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.19) Gecko/2010031422 Firefox/3.0.19
    == Plugins installed
    ==
    *-Default Plug-in
    *RealPlayer(tm) LiveConnect-Enabled Plug-In
    *6.0.12.1662
    *Office Plugin for Netscape Navigator
    *Google Update
    *Shockwave Flash 10.1 r53
    *Yahoo Application State Plugin version 1.0.0.7
    *Next Generation Java Plug-in 1.6.0_18 for Mozilla browsers
    *Adobe PDF Plug-In For Firefox and Netscape
    *DRM Netscape Network Object
    *Npdsplay dll
    *DRM Store Netscape Plugin

    Please let me tell you that I Expert Decomposition may be of any Version of Firefox or Thunder Bird.

Maybe you are looking for