Problem in uploading an image into a CM repository!!

Hi All,
     I am trying to use the Fileupload element in JSP dynpage.
     My screen has the Fileupload element and a button.
     <b>I want to upload an image into a CM repository.</b>
     I have put <hbj:form id="myFormId" encodingType="multipart/form-data" > in my jsp page.
     The <b>'onClick'</b> method is <b>'onLoadFile'</b>.
     <i><b>The following is my code:</b></i>
public void onLoadFile(Event event)
               FileUpload fu =
                    (FileUpload) this.getComponentByName("myfileupload");
               if (fu != null) {
                    //    Get file parameters
                    IFileParam fileParam = fu.getFile();
                    //    Get the temporary file name
                    File f = fileParam.getFile();
                    String fileName = fileParam.getFileName();
                    //    Get the selected file name
                    String ivSelectedFileName = fu.getFile().getSelectedFileName();
                    try {
                         int len = (int) f.length();
                         byte a[] = new byte[len];
                         FileInputStream fin = new FileInputStream(f);
                         fin.read(a);
                         String FileContent = a.toString();
                         IPortalComponentRequest request =
                              (IPortalComponentRequest) this.getRequest();
                         com.sapportals.portal.security.usermanagement.IUser user =
                              (com.sapportals.portal.security.usermanagement.IUser) request.getUser().getUser();
                         IResourceFactory factory = ResourceFactory.getInstance();
                         IResourceContext context = new ResourceContext(user);
                         RID rid = RID.getRID("/documents/test");
                         IResource resource = factory.getResource(rid, context);
                         if (resource != null) {
                              ICollection parent =
                                   (ICollection) ResourceFactory
                                        .getInstance()
                                        .getResource(
                                        rid,
                                        context);
                              String out = new String(FileContent);
                              ByteArrayInputStream data =
                                   new ByteArrayInputStream(out.getBytes());
                              IContent content =
                                   new Content(data, "text/html", data.available());
                              IResource fileResource =
                                   parent.createResource(fileName, null, content);
                    } catch (Exception e) {
               <b>..... REMAINING CODE...</b>
I uploaded <b>abc.jpg (<i>size: 2KB</i>)</b>, then, an image file with the same-name is being created in the <b>/documents/test</b> folder but the size is <b>10Bytes</b> only. <b>I am not able to see the image</b> too.
Can any1 help me plzzzz??? Would appreciate any kind of help.
Thanks in advance.
<b>
Regards,
Sai Krishna.</b>

I would guess that this is because of the way you try to read the file contents. Maybe you should add some debug statements to find out what you're realling setting as content. It's certainly not KM's fault.
The following sequence of statements looks wrong:
nt len = (int) f.length();
byte a[] = new byte[len];
FileInputStream fin = new FileInputStream(f);
fin.read(a);
String FileContent = a.toString();
IPortalComponentRequest request =
(IPortalComponentRequest) this.getRequest();
com.sapportals.portal.security.usermanagement.IUser user =
(com.sapportals.portal.security.usermanagement.IUser) request.getUser().getUser();
IResourceFactory factory = ResourceFactory.getInstance();
IResourceContext context = new ResourceContext(user);
RID rid = RID.getRID("/documents/test");
IResource resource = factory.getResource(rid, context);
if (resource != null) {
ICollection parent =
(ICollection) ResourceFactory
.getInstance()
.getResource(
rid,
context);
String out = new String(FileContent);
ByteArrayInputStream data =
new ByteArrayInputStream(out.getBytes());
IContent content =
new Content(data, "text/html", data.available());
Why don't you just pass the FileInputStream into the Content object's constructor???
Best regards, Julian

Similar Messages

  • Problems while uploading text documents into Unicode Database

    I just upgraded our database from 9iR1 to 9iR2 (9.2.0.1.0). The server
    character set is AL32UTF8. Now I'm facing a problem when
    uploading text documents into the database via a web frontend.
    I use the upload table defined for the PL/SQL Database Access Descriptor:
    create table TB_UPLOAD (
    NAME VARCHAR2(256) not null,
    MIME_TYPE VARCHAR2(128),
    DOC_SIZE NUMBER,
    DAD_CHARSET VARCHAR2(128),
    LAST_UPDATED DATE,
    CONTENT_TYPE VARCHAR2(128),
    BLOB_CONTENT BLOB);
    After uploading a text document containing the two words "hallo welt",
    the following statement returns not "hallo welt", but "68616C6C6F2077656C74":
    declare
    b_loc blob;
    v_amount integer := 100;
    v_buffer varchar2(100);
    v_offset integer := 1;
    begin
    select blob_content into b_loc from tb_upload where name like 'mydoc.txt';
    dbms_lob.read(b_loc, v_amount, v_offset, v_buffer);
    htp.prn(v_buffer);
    end;
    What is this? I studied the documentation, but didn't found a solution.
    When trying to use Oracle's built-in procedure wpg_docload.download_file,
    the content is shown the way it should be. Unfortunately, I can't use
    wpg_docload.download_file in order to copy the BLOB content to another table.
    Any hints would be appreciated!
    Thanks so much in advance!
    Roman
    E-Mail: [email protected]

    Hi Roman,
    the upload uses a BLOB (Binary Lob). Your Document is
    stored as is in the binary representation. If you
    use dbms_lob.read on a blob and your buffer is a varchar2 the binary representation is not translated!!!
    use a raw for the buffer and utl_raw.cast_to_varchar2
    to do the conversion to varchar.
    try this
    Procedure SHOW_DOC(p_name doc_test.name%TYPE)
    IS
    v_len number;
    v_mime_type tb_upload.mime_type%TYPE;
    v_offset integer := 1;
    v_Buf_size integer := 32767;
    v_buf raw(32767);
    v_blob blob;
    v_Doc_name varchar2(1000);
    BEGIN
    v_doc_name := url_Decode(p_name);
    select mime_type,doc_size,blob_content
    into v_mime_Type,v_len,v_blob
    from tb_upload
    where name = v_doc_name;
    OWA_UTIL.MIME_HEADER(v_Mime_Type);
    begin
    LOOP
    DBMS_LOB.READ(v_blob,v_buf_size,v_offset,v_buf);
    HTP.PRN(UTL_RAW.CAST_TO_VARCHAR2(v_buf));
    v_offset := v_offset + v_buf_size;
    END LOOP;
    exception
    when no_data_found then
    null;
    end;
    END;
    HTH
    detlev

  • Problems while uploading text documents into Database

    I just upgraded our database from 9iR1 to 9iR2 (9.2.0.1.0). The server
    character set is AL32UTF8. Now I'm facing a problem when
    uploading text documents into the database via a web frontend.
    I use the upload table defined for the PL/SQL Database Access Descriptor:
    create table TB_UPLOAD (
    NAME VARCHAR2(256) not null,
    MIME_TYPE VARCHAR2(128),
    DOC_SIZE NUMBER,
    DAD_CHARSET VARCHAR2(128),
    LAST_UPDATED DATE,
    CONTENT_TYPE VARCHAR2(128),
    BLOB_CONTENT BLOB);
    After uploading a text document containing the two words "hallo welt",
    the following statement returns not "hallo welt", but "68616C6C6F2077656C74":
    declare
    b_loc blob;
    v_amount integer := 100;
    v_buffer varchar2(100);
    v_offset integer := 1;
    begin
    select blob_content into b_loc from tb_upload where name like 'mydoc.txt';
    dbms_lob.read(b_loc, v_amount, v_offset, v_buffer);
    htp.prn(v_buffer);
    end;
    What is this? I studied the documentation, but didn't found a solution.
    When trying to use Oracle's built-in procedure wpg_docload.download_file,
    the content is shown the way it should be. Unfortunately, I can't use
    wpg_docload.download_file in order to copy the BLOB content to another table.
    Any hints would be appreciated!
    Thanks so much in advance!
    Roman
    E-Mail: [email protected]

    Hi Roman,
    the upload uses a BLOB (Binary Lob). Your Document is
    stored as is in the binary representation. If you
    use dbms_lob.read on a blob and your buffer is a varchar2 the binary representation is not translated!!!
    use a raw for the buffer and utl_raw.cast_to_varchar2
    to do the conversion to varchar.
    try this
    Procedure SHOW_DOC(p_name doc_test.name%TYPE)
    IS
    v_len number;
    v_mime_type tb_upload.mime_type%TYPE;
    v_offset integer := 1;
    v_Buf_size integer := 32767;
    v_buf raw(32767);
    v_blob blob;
    v_Doc_name varchar2(1000);
    BEGIN
    v_doc_name := url_Decode(p_name);
    select mime_type,doc_size,blob_content
    into v_mime_Type,v_len,v_blob
    from tb_upload
    where name = v_doc_name;
    OWA_UTIL.MIME_HEADER(v_Mime_Type);
    begin
    LOOP
    DBMS_LOB.READ(v_blob,v_buf_size,v_offset,v_buf);
    HTP.PRN(UTL_RAW.CAST_TO_VARCHAR2(v_buf));
    v_offset := v_offset + v_buf_size;
    END LOOP;
    exception
    when no_data_found then
    null;
    end;
    END;
    HTH
    detlev

  • Problems while uploading company logo into sap script

    Hi Experts,
      When i am inserting company logo into sap scripts, i successfully uploaded, but the problem is i am getting black and white image instead of color,but in RSTXLDMC i am giving parameter as BCOL only, could anybody help to get my problem resolved. it is very urgent. The logo which i am inserting is colored.
    bye
    M.Rajendra Singh

    HI
    GOOD
    How to Upload graphics (IMAGE) to your Sapscript?
    Command in your Sapscript
    /: INCLUDE Z_YOUR_LOGO OBJECT TEXT ID ST LANGUAGE E
    These are the steps to be followed for uploading graphics in R/3 system 
    1.   First save the file as BMP 
    2.   Open the BMP file in IMaging (Goto -> Programs -> Accessories -> Imaging) and 
          make it Zoom as 100% and save as *.TIFF 
    3.   Open SE38 and execute program RSTXLDMC
    4.   Give your TIFF file path name 
    5.   Select Bcol (for Color) 
    6.   TEXT ID will be ZHEX-MACRO-*. 
    7.   Inplace of * write your own logo name (ZCOMPANYLOGO) 
    8.   Execute the program 
    9.   Now Goto SE71 create your ZFORM 
    10. Create logo window 
    11. Goto text element of logo window 
    or
    In 4.6x :-
    1.  Goto SE71 Change the mode to GRAPHICAL 
    2.  Choose the Graph Tabstrips
    3.  Now type in some name for the LOGO WINDOW 
    4.  Press the IMPORT BUTTON and then IMPORT the BMP file from your DESKTOP 
    5.  The code will be written automatically. You just need to drag and drop wherever you want
         the graphics to be. 
    Please note that in 4.6c onwards, you can also used Windows Bitmap file ( .BMP).
    THANKS
    MRUTYUN

  • Problem in saving the image into SQL database..

    Hello,
    In my application I have to save image file (say jpg) into the database and retrieve back and display it on the applet. I am through with grabbing the pixels of the image & sending the pixel array to the servlet but I am struck in how to store the image into the database and retrieve the same.
    Can anybody please help me in this regard... its really urgent...
    Thanks in advance
    Swarna

    Hello.
    I've been researching this problem (saving images in a MySQL database) in order to accomplish a task I was assigned to. Finally I was able to do it. I'd be glad if it will be of any use.
    First of all: the original question was related to an applet. So, the post from rkippen should be read. It says almost everything, leaving the code job for us. Since I managed to write some code, I'll put it here, but I'm not dealing with the byte transferring issue.
    To obtain a byte array from a file I'd open the file with FileInputStream and use a loop to read bytes from it and save them into a ByteArrayOutputStream object. The ByteArrayOutputStream class has a method named �toByteArray()� which returns an array of bytes (byte [] b = baos.toByteArray()) that can be transferred in a socket connection, as said by rkippen.
    My problem was to save an image captured by a web camera. I had an Image object, which I converted into a byte array and saved into the database. Eventually I had to read the image and show it to the user.
    The table in the MySQL database could be:
    CREATE TABLE  test (
      id int(11) NOT NULL auto_increment,
      img blob NOT NULL,
      PRIMARY KEY  (id)
    )I had problems trying to use the �setBlob� and �getBlob� methods in the Statement object, so I used the �setBytes� and �getBytes� methods . In the end, I liked these methods most because they where more suitable to my application.
    The database operations are:
        public int insertImage(Image image) throws SQLException {
            int id = -1;
            String sql = "insert into test (img) values (?)\n";
            PreparedStatement ps = this.getStatement(sql);  // this method is trivial
            byte [] bytes = this.getBytes(imagem); // * see below
            ps.setBytes(1, bytes);
            ps.executeUpdate();
            id = ps.getGeneratedKeys().getInt(0); //Actually I couldn't make this line work yet.
            return id;
        public Image selectImage(int id) throws SQLException {
            Image img = null;
            String sql = "select img from test where id = ?\n";
            PreparedStatement ps = getStatement(sql);
            ps.setInt(1, id);
            ResultSet rs = ps.executeQuery();
            if (rs.next()) {
                byte [] bytes = rs.getBytes(1);
                img = this.getImage(bytes); // * see below
            return img;
        }* If the bytes are read directly from a file, I think it is not necessary to convert it into an Image. Just send the bytes to the database method would work. On the other hand, if the image read form the DB will be written directly into files, the bytes obtained from rs.getBytes(1) would be enough.
    The image operations are:
        public byte [] getBytes(Image image) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                ImageIO.write(this.getBufferedImage(image), "JPEG", baos);
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            return baos.toByteArray();
        public Image getImage(byte [] bytes)  {
            Image image = null;
            ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
            try {
                image = ImageIO.read(bais);
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            return image;
        public BufferedImage getBufferedImage(Image image) {
            int width = image.getWidth(null);
            int height = image.getHeight(null);
            BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
            Graphics2D g2d = bi.createGraphics();
            g2d.drawImage(image, 0, 0, null);
            return bi;
        }That's it. I hope it is useful.

  • Problem in Uploading Transparent images in SE78

    Hi,
         I am trying to upload an image (Company Logo) with a transparent background in SE78. The file format at the time of upload is TIFF (since bitmap does not support transparency).
         However I get an error message "Erroneous TIFF file". Can anyone help me out please, as we have a requirement to print this logo on a check using a laser printer.
    Thanks and Regards,
    Aditya

    Hello All,
                I got the solution to this problem.
                You take an image and save it as a 256 colour bitmap (Using for example the windows Paint application)
                Then you upload this image via transaction SE78 as a graphic.
                <b>When you save the bitmap as a 256 colour BMP file</b>, then the white background stays as a "White/Transparent Background"...which means for a laser printer...it does not try to print a "White Area".
                 Instead, if you use a 24-bit high resolution bitmap, you could get a Creamy layer in the white area of the BMP and this is not desired if you are printing using a laser printer on a coloured paper
                  So use a 256 colour Bitmap for these "Transparent" logos
    Regards,
    Aditya

  • Problem when upload a image

    i have to upload an image in #WORKSPACE_IMAGES# , but when i choose my file, the browser view a blank page and i can't upload my image....how can i do?

    Hi massimorigo!<br>
    <br>
    I don't know what browser you're using. I had the same problems with Mozilla, Firefox and Konqueror.<br>
    Forget the Konqueror. In Mozilla or Firefox just change the Standard Language to "ENGLISH". I don't know why but it works!<br>
    <p>
    ~Dietmar

  • Need to Upload the image into XMII server from a desktop

    Hi,
    Can anyone let me know how to upload the image from my laptop on to the server which i should be using in my pages. I tried using Image Loader and Image Saver. But it lead me no where. Is there a detailed documentation for this ?
    Thanks for your help in Advance.
    Regards,
    Deepthi lakshmi.A.

    Hi Deepti,
    Could you give some details on what you are trying to achieve.
    Is this a use case scenario where images need to be uploaded by a handful of people using some web UI?
    or
    Is this a use case scenario where you wish to upload images from the harddrive of absolutely any user?
    The reason for my questions is as follows.
    If you wish to allow some high-level (technically savvy) users the ability to upload images to be shown in dynamic content for remainder of the public, you could, in theory, set up a network directory that xMII is able to see.  These High-Level users could drop their images in the folder and specify the path in a text box.
    You could go one step further and use Get Folder List action from within an Xacute transaction and display the list of images in this folder on a web UI.  Users could pick the image from the list and "Bob's your Uncle!".
    Hope this helps,
    Cheers,
    Jai.

  • Problem while uploading Portal Theme into R/3 System?

    Hello Guru's
    I am trying to upload Portal Theme into R/3 system.
    We have a program which will upload to a given path.
    T.Code SE38 Program name BSP_update_mimerepos.
    When I upload the theme using the program I get some folders,
    like Common, r, UR
    when cross checked with the standard I see css files are missing when uploading.
    please help me on resolving this.
    Thanks in Advance.
    Points will be rewarded for helpful inputs.
    Regards,
    Pramod

    solved went with WD_THEMES report to upload the theme to R/3 system.
    search in forum to find out the solution.
    cheers-
    Pramod

  • Uploading Safari images into 'Blackboard' doesn't work.

    I am using an iMac G5, OS X (10.4.8), 2Ghz PowerPC with 512 MG of RAM.
    I am able to successfully create .html files with various programs (Nvu, Dreamweaver, Mozilla,) and I can open those documents and see the images in them in my default Safari browser (as well Explorer, Firefox, Mozilla,). I USED to able to upload those documents successfully into the 'Blackboard' program my college uses. Here I can't be helpful: I did something -perhaps changed my browser from Netscape Navigator to Safari, but I can't guarantee that's the problem- so that the uploads show the text but no longer load the images. When I open the documents in the Blackboard program, the images don't show as broken, they show as question marks in a small blue square in the center of the missing image.
    I have tried the Blackboard help site, and all the image-loading recommendations I see on this forum. I've tried going to 'Safari> Preferences> Appearance> Display images when the page opens' and making sure that box is checked. I've tried finding 'Safari> File> Publish as> and making sure images are published, but I can't find that option on my Mac. None of the tech support at school can solve the problem -though the process supposedly works just fine on a PC. I have struggled with this for months, and since I teach art history and need to show images, it is making my life miserable. Any help would be much appreciated.
    Carolyn
    iMac G5   Mac OS X (10.4.8)   PowerMac8,2

    Thanks for the rapid response! A pity I don't have the language to be of more help.
    First, 'Blackboard.edu' is a service institutions of education subscribe to. Faculty users publish their class webpages, and can keep those inhouse or make them available to the www. So, I've been publishing web pages (in house) for my classes for years. This year I've run into problems with getting my .html documents to load the images contained in them. I do believe my colleagues have uploaded my documents successfully onto their Blackboards via PCs, leading me to believe this is a Mac problem . . .
    Someone suggested this was a browser problem, so I kept trying different default browsers, searching their preferences for any boxes that needed to be checked to allow images. Each time I upload I am told the upload was sucessful -I get no error messages- and each time the images don't load.
    I defaulted to Safari and did as you suggested, and there was a slight change. Instead of the blue-box question mark, the image title was displayed, but still no image.
    iMac G5   Mac OS X (10.4.8)   PowerMac8,2. / 2 GHz PowerPC

  • Problem to upload the data into internal table record length more than 6000

    Hi all
            I stuck with this problem from past 3 days. I have to upload the data from excel sheet. iam making it tab delimited and trying to upload from gui_upload. but in the structure of file, we have, one field of 4000 characters, and other fields of 255 characters.
    how can i upload this into internal table . From excel sheet or from tab delimeted or any other format? or any special function module is there?  while iam doing this its truncating the datat 255 characters and not uploading the other fields also...
    can any one of you help me out. ASAP
    thnks in advance

    from one of the forum iam just pasting code which it is used in lsmw, try the same logic in ur code hope it can work.
    you have to create multiple lines with do...enddo loop., like this:
    (assuming excel_long_text-text is 924 characters long, 7 lines X 132 char)
    __GLOBAL_DATA__
    data: offset type i,
    text_132(132) type c.
    __BEGIN_OF_RECORD__ Before Using Conversion Rules
    Rule : Default Settings Modified
    Code: /sapdmc/ltxtl = init_/sapdmc/ltxtl.
    CLEAR offset.
    DO 7 TIMES.
    text_132 = excel_long_text-text+offset(132).
    offset = offset + 132.
    __END_OF_RECORD__ After Using Conversion Rules
    Rule : Default Settings Modified
    Code: transfer_record.
    ENDDO.
    also check this
    COMMIT_TEXT
    To load long text into SAP
    READ_TEXT
    To load long text into SAP

  • Lenovo Vibe X( S960) hangs on while uploading the images into Whatsapp.

    Hi ,
    I purchased the Vibe x(S960) 3 days back and when I try to upload photos in the Whatapp, mobile hangs and not even able to come out of that problem. Needs to wait until battery gets dry. ( some time I have wait for more than 3 hours to battery gets dry).. please have a look into this ASAP and let me know if you have any fix for the problem.
    If no fix is exist. please provide me the some temprory fix atleast.

    please remember that this is a peer to peer forum, provided by Lenovo in order that members may seek assistance from others and share their experiences, not a dedicated support site. There is a Leonovo presence here but unfortunately there is no guarantee you will receive a direct response.
    Regards
    Andy  ______________________________________
    Please remember to come back and mark the post that you feel solved your question as the solution, it earns the member + points
    Did you find a post helpfull? You can thank the member by clicking on the star to the left awarding them Kudos Please add your type, model number and OS to your signature, it helps to help you. Forum Search Option T430 2347-G7U W8 x64, Yoga 10 HD+, Tablet 1838-2BG, T61p 6460-67G W7 x64, T43p 2668-G2G XP, T23 2647-9LG XP, plus a few more. FYI Unsolicited Personal Messages will be ignored.
      Deutsche Community     Comunidad en Español    English Community Русскоязычное Сообщество
    PepperonI blog 

  • Upload/download image into Mysql

    Hi there,
    I'm trying to place an Image object into a mysql database, and then also have the ability to download it. I'm using a BLOB column type to store the image. I dont really know how to do this, i've looked at http://forum.java.sun.com/thread.jsp?forum=48&thread=446603 which is kind of relavant but I just want to load the image.
    Any help would be cool,
    Steve

    That is exaclty what he is doing, if you notice
    dPhoto = new ImageIcon(b);he has created a new image that he can now display in a swing gui

  • Problem exporting Illustrator gradient images into Indesign.

    I created and overlapped 3 gradient images in Illustrator cs6 and saved @ an eps file.  When imported into Indesign thin white lines appear where the images overlap.  How to fix?

    Thanx Kris -
    I saved file @ a pdf and it exported perfectly.
    Will also try your suggestion.

  • Problem in upload flat file into bw-bps using web browser

    Hi All,
    I have follwed the steps as per the how to guide to upload flat file,its seems to be fine but when try to upload by running the URL its giving error "Value of variable Data Slice Global ( ZFIE0ALL ) cannot be determined " and warning "Errors occurred when executing planning function TUPLOAD(EXIT FOR UPLOAD DATA)/T0000000(WEB UPLOAD".
    Since i am new to BW/BPS , also let me know, how test it , when i run file_upload URL directly its giving follwing error.
    SAP Note
         The following error text was processed in the system:
         An exception with the type CX_SY_REF_IS_INITIAL occurred, but was neither      handled locally, nor declared in a RAISING clause
    When i run page1 url and if i file_load url, then its prompt me to see upload function, path for flat file. But when enter path of flat file and press upload function button ts giving error "Value of variable Data Slice Global ( ZFIE0ALL ) cannot be determined " and warning "Errors occurred when executing planning function TUPLOAD(EXIT FOR UPLOAD DATA)/T0000000(WEB UPLOAD".
    FYI..i am using new design HTMLB option in how-to-doc.
    Please help me to resolve this. Thanks in advance.
    Also pls let me know can i debug this application?How ?
    Vishal
    Message was edited by:
            vishal kashyap
    Message was edited by:
            vishal kashyap

    Hi Vishal
    Can u guide me , by what condition the data is selected in XTH_data ( Hashed table ) before the data is written by flat file function module .
    Reply me ASAP ,
    Thanks
    Anup Singh

Maybe you are looking for