Uploading a file from a J2ME application

Ok, obviously this is either not interesting, or no one really knows what to do, I would love any ideas even if they dont work, just anything that would help would be great :)
I am extremely new to servlet programming and reasonably new to J2ME. I want to upload a file from my device to a central server. I am not sure how to go about starting this. I have a html form that requests a file and posts it to the servlet fine, but I am not sure how I would get my J2ME application to do the same. Do I replicate the html from with in the program? Any help would be much appreciated.
My basic servlet and Java code is:
Java
public String sendPostRequest(String urlstring) throws IOException {
              HttpConnection hc = null;
              DataInputStream dis = null;
              DataOutputStream dos = null;
              String message = "";
              // the request body
              FileSystem fs = new FileSystem();
              byte[] file = fs.returnFile("c:/other/dot/helloworld.txt");
              if(file != null){
                   String fileString = ("file=" + new String(file));
                   try {
                     // an HttpConnection with both read and write access
                     hc = (HttpConnection)Connector.open(urlstring, Connector.READ_WRITE);
                     // set the request method to POST
                     hc.setRequestMethod(HttpConnection.POST);
                     // set request type
                     // Could possibly need to be "application/x-www-form-urlencoded"????????????????????????????????
                     hc.setRequestProperty("Content-Type", "multipart/form-data");
                     hc.setRequestProperty("Content-Length", fileString.length()+ "" );
                     // obtain DataOutputStream for sending the request string
                     dos = hc.openDataOutputStream();
                     byte[] requestBody = fileString.getBytes();
                     // send request string to Web server
                     for (int i = 0; i < requestBody.length; i++) {
                       dos.writeByte(requestBody);
               // flush it out
               dos.flush();
               // obtain DataInputStream for receiving server responses
               dis = new DataInputStream(hc.openInputStream());
               // retrieve the responses from Web server
               int ch;
               while ((ch = dis.read()) != -1) {
               message = message + (char) ch;
               } finally {
               // free up i/o streams and http connection
               if (hc != null)hc.close();
               if (dis != null)dis.close();
               if (dos != null)dos.close();
Servlet
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.oreilly.servlet.MultipartRequest;
public class DNTUpload extends HttpServlet{
    public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{
        res.setContentType("text/html");
        PrintWriter out = res.getWriter();
        try{
            MultipartRequest multi = new MultipartRequest(req, "C:\\Servlets+JSP\\DNT", 5*1024*1024);
            Enumeration files = multi.getFileNames();
            String name = (String)files.nextElement();
            File f = multi.getFile(name);
            if(f != null){
                out.println("<HTML>");
            out.println("<HEAD><TITLE>FileUploader</TITLE></HEAD>");
            out.println("<BODY>");
            out.println("<H1>Should have saved file</H1>");
            out.println("</BODY>");
            out.println("</HTML>");
            else{
                 res.setHeader("valserror", "ERROR");
        }catch(Exception e){
            out.println("<HTML>");
            out.println("<BODY>");
            out.println("failure!!");
            out.println("</BODY>");
            out.println("</HTML>");
Message was edited by:
-fluffy-

I've only done one small j2me program and not recently, but here is a link that can give you some of the basics: http://today.java.net/pub/a/today/2005/02/09/j2me1.html
I'm guessing, but I believe you have to use http sockets to accomplish a file transfer with a phone. Also, there are some limitations with full sockets depending on which type of phone you using to write your app to.
Hope that helps!

Similar Messages

  • Upload file from Presentation to Application

    Hi Friends,
    I  M uploading EXEL file  from presentation to application server.
    but in the transaction AL11 when i double click the file path ,i can not see the EXEL data. it is appearing the dump data. that way,  i m finding  the dump data in internal table also . what can i do for uploading EXEL file to application server.
    please help me.
    Thanks,
    Rohini

    hai rohini
    To upload excel file to AL11 Please refer to the given below code:
    data : if_intern type  kcde_cells occurs 0 with header line.
      data : vf_index type i.
      data : vf_start_col type i value '1',
             vf_end_col   type i value '256'.
      field-symbols : <fs>.
    * ----------- " Define Internal tables for ABAP.
    data: begin of i_mat OCCURS 10,
          empc(5),
          name(12),
          Age(3),
          end of i_mat.
    * ----------- " Define data variables for ABAP.
    *             " Define data variables for Excel Upload.
    data: p_text type natxt.
    data: dataset(150) type c.:
    * ----------- " Selection-Screen.
    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE text-001.
    parameters: p_file2  type rlgrap-filename,
                p_brow2 type i,
                p_erow2 type i.
    SELECTION-SCREEN END OF BLOCK B1.
    * ----------- " At Selection- screen.
    at selection-screen on value-request for p_file2.
      call function 'KD_GET_FILENAME_ON_F4'
        EXPORTING
          program_name = syst-repid
        CHANGING
          file_name    = p_file2.
    * ----------- " Start of ABAP SQL Commands
    START-OF-SELECTION.
    *  dataset = '/tmp/new.xls'.
       dataset = '/tmp/new.xls'.
      if rg1 = 'X'.
       if p_file2 is not initial and
          p_brow2 is not initial and
          p_erow2 is not initial.
    call function 'KCD_EXCEL_OLE_TO_INT_CONVERT'
        EXPORTING
          filename    = p_filename
          i_begin_col = vf_start_col
          i_begin_row = p_brow2
          i_end_col   = vf_end_col
          i_end_row   = p_erow2
        TABLES
          intern      = if_intern.
      if if_intern[] is initial.
        p_text = 'No Data Uploaded'.
      else.
        sort if_intern by row col.
        loop at if_intern.
          move : if_intern-col to vf_index.
          assign component vf_index of structure p_download to <fs>.
          move : if_intern-value to <fs>.
          at end of row.
            append p_download.
            clear p_download.
          endat.
        endloop.
      endif.
    delete dataset dataset.
      open dataset dataset for output in text mode encoding default.
      loop at i_mat.
        if sy-subrc eq 0.
          transfer i_mat to dataset.
        endif.
      endloop.
      close dataset dataset.

  • How to upload XML file from Application server.

    Hi,
    How to upload XML file from Application server.Please tell me as early as possible.
    Regards,
    Sagar.

    Hi,
    parameters : p_file type ibipparms-path obligatory.
    ***DOWNLOAD---->SAP INTO EXCEL
    filename1 = p_file.
    call function 'GUI_DOWNLOAD'
      exporting
      BIN_FILESIZE                    =
        filename                        = filename1
        filetype                        = 'ASC'
      APPEND                          = ' '
      WRITE_FIELD_SEPARATOR           = 'X'
      HEADER                          = '00'
      TRUNC_TRAILING_BLANKS           = ' '
      WRITE_LF                        = 'X'
      COL_SELECT                      = ' '
      COL_SELECT_MASK                 = ' '
      DAT_MODE                        = ' '
      CONFIRM_OVERWRITE               = ' '
      NO_AUTH_CHECK                   = ' '
      CODEPAGE                        = ' '
      IGNORE_CERR                     = ABAP_TRUE
      REPLACEMENT                     = '#'
      WRITE_BOM                       = ' '
      TRUNC_TRAILING_BLANKS_EOL       = 'X'
      WK1_N_FORMAT                    = ' '
      WK1_N_SIZE                      = ' '
      WK1_T_FORMAT                    = ' '
      WK1_T_SIZE                      = ' '
    IMPORTING
      FILELENGTH                      =
      tables
        data_tab                        = it_stock
      FIELDNAMES                      =
    exceptions
       file_write_error                = 1
       no_batch                        = 2
       gui_refuse_filetransfer         = 3
       invalid_type                    = 4
       no_authority                    = 5
       unknown_error                   = 6
       header_not_allowed              = 7
       separator_not_allowed           = 8
       filesize_not_allowed            = 9
       header_too_long                 = 10
       dp_error_create                 = 11
       dp_error_send                   = 12
       dp_error_write                  = 13
       unknown_dp_error                = 14
       access_denied                   = 15
       dp_out_of_memory                = 16
       disk_full                       = 17
       dp_timeout                      = 18
       file_not_found                  = 19
       dataprovider_exception          = 20
       control_flush_error             = 21
       others                          = 22
    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,
    Deepthi.

  • Error while uploading the file from Allpcation server in LSMW-7th step

    Hi Experts,
    what should be the specific CODE PAGE should be maintained while uploading the file from application server in LSMW-7th Step
    Thanks in advance,
    KSR

    Hi
    I mean that there is any seperate CODE PAGE which comes at the bottom of screen while uploading the file from the application server in 7th step.
    Is there any specific CODE PAGE to be maintained...
    Thanks in advance
    Oarsk

  • How to upload pdf file from windows cell phone?

    How to upload pdf file from windows cell phone?

    You can do this in steps.. First use the built in method for uploading a file into the flows files object, Next you would copy the file out to an Oracle built directory on your UNIX box using utl_file.put_raw..
    Here is a link to show you how to upload files in an APEX application [http://download.oracle.com/docs/cd/B31036_01/doc/appdev.22/b28839/up_dn_files.htm]
    And here is a link to show you how to use utl_file.put_raw.. [http://psoug.org/reference/utl_file.html], item is towards the bottom of the screen..
    Thank you,
    Tony Miller
    Webster, TX

  • Upload a file to portal--- BW application server.

    Dear All,
    I have requirement where some part of business does not have SAP installed. But we would like to extract data from these business too.
    So just wanted to know if we can have a scenario where user will upload the data to the portal (this is just a web portal). Can this be done?
    Secondly, if the can be done, can we extract the file from portal to application server? From application then it becomes very simple to upload to data targets in BW.
    Please help in this regard.
    Thanks,
    Sandeep

    Assign an ID (e.g. 1234) to the uploaded file. You should abstract the store
    so that it will work on the file system or in the database.
    The JSP will include an image ref to that ID, e.g.
    http://www.myco.com/myapp/imageservlet?id=1234
    The image servlet will retrieve and stream the image. It has to set content
    type etc. You should also verify that the current user has access to the
    requested image if security/privacy is an issue.
    Peace,
    Cameron Purdy
    Tangosol, Inc.
    http://www.tangosol.com/coherence.jsp
    Tangosol Coherence: Clustered Replicated Cache for Weblogic
    "newsgroups.bea.com" <[email protected]> wrote in message
    news:3daadaa5$[email protected]..
    Imp struggling to find a way of uploading an image file from the browserto
    the app server (wl 6.1), where the uploaded image will to be included as
    part of a JSP file.
    ** Note
    - this part of Managed Cluster, the uploaded directory is NFS mounted
    between the managed servers
    - we deploy using EAR's from the admin server.
    I am able to upload but, cant get the uploaded image to display as partof
    a JSP,
    Our 5.1 WL server work perfectly using a standard exploaded directory !
    I have logged this as a call at BEA, but they have not been able to offerme
    a solution yet.
    Regards
    Roland

  • Uploading excel files from ITS to sap

    Hi all,
    I want to upload excel files from ITS to sap system ECC 6.0 .I am using standalone ITS.Someone please help me find a solution for this.What are the steps involved in it?
    Thanks in advance
    Shinu

    Hi Shinu,
    this seems to be a misunderstanding. The ITS does not have excel files.
    Did you mean to say that you have an application which allows to upload
    files? This application might work using the webgui service of the ITS.
    Try it out!
    best regards
    Tobias

  • Upload XL file from FTP server

    Hi All,
    Can anybady help me, how to upload Excel file from FTP server.
    Thanks
    Sri
    Edited by: srikanthn on Apr 14, 2010 6:31 PM

    Hello
    How about using SAPFTP?
    I hope SAP note 130106 will guide you on this.
    Thanks
    koju

  • To upload a file from client machine to server machine

    Hi everybody!
    Could anyone plz help me. I am struck in a problem
    I want to transfer a file from client's machine to server but I am not able to upload
    It is tranferring the file only to the local machine
    I am using orielley package It is transferring files only to my local machine but not to the server .Can anyone correct it. It's very urgent
    how to write the relative path for server
    I am using this path and it is not uploading
    MultipartRequest multi = new MultipartRequest(request, "../<administrator>:<dev2daask>@dev2:C:/123data/", 5 * 1024 * 1024);
    Here is my code:
    <%@ page import="java.util.*" %>
    <%@ page import="javax.servlet.*" %>
    <%@ page import="javax.servlet.http.*" %>
    <%@ page import="java.io.*" %>
    <%@ page import="com.oreilly.servlet.MultipartRequest"%>
    <%
    try {
    // Blindly take it on faith this is a multipart/form-data request
    // Construct a MultipartRequest to help read the information.
    // Pass in the request, a directory to saves files to, and the
    // maximum POST size we should attempt to handle.
    // Here we (rudely) write to the server root and impose 5 Meg limit.
    MultipartRequest multi = new MultipartRequest(request, "../<administrator>:<dev2daask>@dev2:C:/123data/", 5 * 1024 * 1024);
    out.println("<HTML>");
    out.println("<HEAD><TITLE>UploadTest</TITLE></HEAD>");
    out.println("<BODY>");
    out.println("<H1>UploadTest</H1>");
    // Print the parameters we received
    out.println("<H3>Params:</H3>");
    out.println("<PRE>");
    Enumeration params = multi.getParameterNames();
    while (params.hasMoreElements()) {
    String name = (String)params.nextElement();
    String value = multi.getParameter(name);
    out.println(name + " = " + value);
    out.println("</PRE>");
    // Show which files we received
    out.println("<H3>Files:</H3>");
    out.println("<PRE>");
    Enumeration files = multi.getFileNames();
    while (files.hasMoreElements()) {
    String name = (String)files.nextElement();
    String filename = multi.getFilesystemName(name);
    String type = multi.getContentType(name);
    File f = multi.getFile(name);
    out.println("name: " + name);
    out.println("filename: " + filename);
    out.println("type: " + type);
    if (f != null) {
    out.println("length: " + f.length());
    out.println();
    out.println("</PRE>");
    catch (Exception e) {
    out.println("<PRE>");
    out.println("</PRE>");
    out.println("</BODY></HTML>");
    %>

    you have not understood my point
    how does this code will run on servlet when I want to upload a file from client's
    machine to server machine
    what I am doing is I am giving an option to the user that he/she can browse the file and then select any file and finally it's action is post in the jsp form for which I have sent the code
    All the computers are connected in LAN
    So how to upload a file from client's machine to server's machine
    Plz give me a solution

  • Help please to Upload a file from my PC to server's KM

    Hello:
    I can't Upload correctly a file from my local PC to a KM of the server.
    My problem is after that I've uploaded any file from my PC to KM, sometimes when I open or download it from the KM appears blank, and when I try another way to write the file (out.write()) I've uploaded a bad file that can't be downloaded or opened it. I can't get the file Data of the file for uploading, I need to set it with the fileResource (I tried with fileResource.read(false))
    I use a FileUpload in my view.
    <b>My Context:</b>
    File (node)
         |----fileResource  (com.sap.ide.webdynpro.uielementdefinitions.Resource)
         |----fileData  (binary)   
         |----fileName  (String)
    wdDoInit(){
         IPrivateUploadDownloadKMView.IFileElement fileBind = wdContext.createFileElement();
         wdContext.nodeFile().bind(fileBind);
         IWDAttributeInfo attInfo = wdContext.nodeFile().getNodeInfo().getAttribute("fileData");
         ISimpleTypeModifiable type = attInfo.getModifiableSimpleType();
    onActionSubir(){
          IPrivateUploadDownloadKMView.IFileElement fileElement = wdContext.currentFileElement();
          IWDResource resource = fileElement.getFileResource();
          fileElement.setFileName(resource.getResourceName());
          fileElement.setFileData(fileData);
          byte[] fileData=new byte[resource.read(false).available()];
          fileElement.setFileData(fileData);
          fileName = fileElement.getFileName();
         try{               
               File file = new File(fileName);
               FileOutputStream out = new FileOutputStream(file);
               out.write(fileElement.getFileData());
               out.close();
               fin = new FileInputStream(fileName);
               fin.read();
               Content content = new Content(fin,null, -1);
                IResource newResource = folder.createResource(fileElement.getFileName(),null, content);
          catch(Exception e){
                 IWDMessageManager mm = wdControllerAPI.getComponent().getMessageManager();
                 mm.reportWarning("error: "+e.getMessage());
    Can you help me?, any sugestions to solve my problem or improve my code?
    Regards
    Jonatan.

    If you have got the permission to access <b>content management</b> in portal appliction server consle,then click on content management >select the KM Repository and clik on it.Then right click on <b>folder</b>>new-->upload.After clicking the upload option one page will be open and then you can browse your local file and upload to the KM Repository.

  • How can I upload raw files from my canon g7x to lightroom5

    How can I upload raw files from my canon g7x to lightroom

    See this thread in the official Adobe feedback forum: Why doesn't my version of Photoshop or Lightroom support my camera?

  • How to allow the user to upload a file from their desktop to MII Server?

    Hi,
    Is there a way for the user to specify a file on their local computer to upload to the MII server for processing?  We have a method that works for uploading from a shared network drive, but now the need/desire is to allow the user to upload a file from their desktop.
    Ideally, this would be a file browser that the user would click on to browse their local desktop and select the file and click "Upload" but not sure what's possible?
    This is using 12.1 SP4.
    Thanks for the help.
    Kerby

    [Uploading Documents|Uploading Documents]

  • Upload xml file from aplication server using read dataset, parser error.

    Hi,
    I would like to upload xml file from app. server but parser failed. If I upload this xml file from workstation (using ws_upload) it is correct. For uploading xml file from app. server I use open dataset... read dataset. In loop section I remove '#' char. How do You upload xml file from app server? What Could be incorrect.
    I try to open dataset in binary mode, text mode...
    TYPES: BEGIN OF xml_line,
            data(255) TYPE c,
          END OF xml_line.
    DATA: gt_xml_table TYPE TABLE OF xml_line,
          gs_xml_structure TYPE  xml_line,
          gv_xml_table_size TYPE i.
    OPEN DATASET s FOR INPUT IN BINARY MODE.
      IF sy-subrc <> 0.
        MESSAGE e001(zet) WITH '....'.
      ENDIF.
      DO.
        READ DATASET s INTO gs_xml_structure.
        IF sy-subrc <> 0.
          EXIT.
        ELSE.
         len = STRLEN( gs_xml_structure ).
         len = len - 1.
         check len > 0.
         WRITE gs_xml_structure(len) TO gs_xml_structure.
          APPEND gs_xml_structure TO gt_xml_table.
        ENDIF.
      ENDDO.

    You Can do this too
    parameters: p_file like rlgrap-filename.
    data: subrc like sy-subrc.
      create object me.
      REFRESH t_data.
    *  Open XML File
      CALL METHOD me->CREATE_WITH_FILE
        EXPORTING
          filename = p_file
        RECEIVING
          retcode  = subrc.
    * Saves Data in an itab from XML File.
      CALL METHOD me->get_data
        IMPORTING
          retcode    = subrc
        CHANGING
          dataobject = t_data[].
    Regards,
    Claudio.

  • Timecapsule - opening files from within an application!!

    I have a time capsule... 500Mb
    I have an airport extreme with external hard drive - 250 Mb.
    Through Finder, I can place files on either of these drives and open them from Finder.
    If I open Numbers, or Pages, then try to open any file on Timecapsule, it appears that there are no files
    If I open Number, or Pages, then try to open any file on the Airport Extreme external disk - it works!
    Simple question really.... why cannot I see or open any file from within an application that resides on Timecapsule?? It's driving me crazy!!!
    Message was edited by: GrahamDurkin

    File dialogs have the ability to "group" items, which prohibits you from changing sort options.  The group icon looks like six little squares.  Click on it and instead of grouping by date, group by "none" and then you can change sort orders.

  • How to get the complete path name when uploading a file from servlet

    Hi,
    I write a servlet to upload a file from html page
    <intput type=file name=fileupload>I am using
    import org.apache.commons.fileupload.to upload file. i want to get the all fields in the form and file name and content of the file also.
    It give the file name only
    String filename= fileItem.getName();
    o/p krish.jpgBut i want complete path naem like
    d:/krishna/images/funny/krish.jpgI serach the API org.apache.commons.fileupload.*
    But i did nt find the method to get it.
    plz help me , which api or method to use here..

    Krishna_Rao_chintu wrote:
    But i need path and have to do some calculations on it.No, you don't. If you have requirements which say you do then the requirements are wrong. You couldn't do anything useful with the path on the client system even if you could get it.
    is there any alternatives in java
    I need path and have to calculate MD5, Presumably you need to calculate MD5 on the contents of the file and not on the name of the file.
    and convert the file to binary format.... etc oprations on itSorry, "convert a file to binary format" is basically meaningless.
    but we can get the content of the file using
    byte [] get()/ getString() methods
    If i get content is there any performance degrades?
    ie if the content is lengthy is it take more time?Take more time than what? Degrading performance from what? It's certainly true that it would be quicker to not upload the file, but that's a pointless comparison. If you have some other process to compare with, let us know what it would be.

Maybe you are looking for

  • Regaring File to IDOC  Useing SOAP Adapter

    Hi ,     Can any one please forward me an File to idoc Useing SOAP ADapter Senario.IF i am wrong please send me a simple senario of useing SOAP Adapter. Regd's Raj

  • Tech and func specs

    Hi, Can anyone send me sample docs on  technical and functional specs to [email protected] what is functional specs and technical specs ? any diff between them ... pls thro some lights on this Thanks in Advance ss

  • Layer Mask to hide certain area of  image

    Hi All, I would be grateful if anyone could help me to figure out how to mask only 1 polygon with cat heads because my cat image is so big until it appears on other polygons. Attached below is my screen shot for better understanding. Any tips and hel

  • What's the best way to ID machines that need Jave SE 6 Update 14?

    I've just read the update release notes ( http://java.sun.com/javase/6/webnotes/6u14.html ) for the Java SE 6 Update 14 and I want to deploy it to our systems. I've never been real good at knowing just how to identify what version of Java a machine h

  • Getting error while deploying woodstock project in jdeveloper

    Hi All, At last I deployed woodstock project in tomcat server and it is working fine but when I am trying to deploy it in jdeveloper I am getting lot of errors like Error: Unable to instantiate tag: webuijsf:page (class: null)  Make sure that the tag