HttpConnection upload image to server

Hi all

I'm new on the server to access the content and I try to send a file of image on my server using the HttpConnection class. I have searched this forum for the same thing, but could not understand my mistake. My requirement is to display an image file in the application server running in Tomcat. Here is my code to access the server. The server expects the image on demand. I don't know how this POST method.

When I have the debug, I get like "500" http response code I replaced the URL like http://125.22.250.67:7070 and I get the response as "200" code, which is the success. Please also review the code for the server.

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
            {
                int length =request.getContentLength();
                log ("file name:"+length);

                String type =request.getContentType();
                log ("content type:"+type);

                ServletInputStream in = request.getInputStream();
                log ("input stream:"+in);

                String path = request.getContentType();
                log ("szname:"+path);
                File f1 = new File(path);

                log("File Name:" + f1.getName());
                log("Path:" + f1.getPath());
                log("Abs Path:" + f1.getAbsolutePath());

             }

. Client code:

        OutputStream out = null;
        InputStream in = null;
        String URL = "http://125.22.250.67:7070/readresponse/noreplica";
        try
        {
            in = this.getClass().getResourceAsStream("/icons.png");
            byte[] postData = IOUtilities.streamToBytes(in);
            int len = postData.length;
            conn = (HttpConnection) Connector.open(URL);
            conn.setRequestMethod(HttpConnection.POST);
            int respCode = conn.getResponseCode();
            if (respCode == HttpConnection.HTTP_OK)
            {
                conn.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_LENGTH,String.valueOf(postData.length));
                conn.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_TYPE,HttpProtocolConstants.CONTENT_TYPE_IMAGE_PNG);

                out = conn.openOutputStream();
                out.write(postData);
            }

Help, please...

You must set the length of the content (all request headers), actually and also write the post data before call you getResponseCode(). Take a look at the documentation for javax.microedition.io.HttpConnection - there is an example of code to make a POST. Although the sample code is not set the content-length header, you should, because your server code is based on it.

Tags: BlackBerry Developers

Similar Questions

  • Uploading images on the server

    Hi all

    My requirement is that the user enters the images and images must be uploaded to the server in the background while the user can continue to perform other tasks at the request. I would like to know what is the best way to implement a background thread that downloads images on the server. Could someone please provide me with a few entries. Thanks in advance.

    Kind regards

    S.A.Norton Stanley

    There is no problem with the background Thread.  I would recommend that you have only one Thread, containing the first element of a list persistent images to send.  Once the image has been sent to it, the Thread deletes the entry for one just sent and resumed the following.  You need good timing around the updating of the list, I use usually vector which is theoretically synchronized correctly but I'm a check anyway.

    The processing of wire has a public Add method that starts the Thread if it is not running.  The Thread stops when there is nothing in the queue.

    All this is pretty standard, I think.  But there are a few things that I think that you may need to add to this transformation to make it more robust:

    (a) you can give the user the option to delete the image once it is sent.  Indeed remember that the user could remove the image before sending it and if treatment should take care of this.

    (b) I would recommend a server component that receives Images.  You can then move the image into pieces because some methods of communication are limited by the size of the data that can be transferred to a single connection.  I would recommend breaking the image into blocks of 64 KB.  You should provide a mechanism to restart here too, so that you can return just the parts in waiting for an image after a failure.

    (c) you need to think about the question to know if the server and intermediate gateways will deal with binary data, or do you need to encode it in text (Base 64 seems to be the way to go if you do).

    (d) you should consider which allows the user to limit communication to specific connections, such as WiFi or 3 G.

    (e) you will need to be very careful about the coding of restart and recovery, so that the treatment doesn't die unexpectedly.

    Hope this is useful.  .

  • uploaded image don't show

    After the download of images on one of the pages of my site, I exported as HTML, and then transferred to my host (via GoDaddy).

    When previewing or HTML format, the images appear quite well as shown;

    1.png

    However, once the site is downloaded, the same page does not display the uploaded images:

    2.png

    Some things I've tried:

    -Reduced each image size and resolution

    -InBrowser mounting

    -Export the image to the file public_html with two options: (1) download all of the files and (2) only changed son

    None of the methods I've tried has worked. Anyone with similar problem and has a solution for this?

    Thank you

    Please check if images are uploaded properly to the folder root also if they are connected properly. This can happen due to the images not linked correctly or not uploaded to the server.

    If everything looks good and then publish the site in British Colombia as a trial site and then check.

    Thank you

    Sanjit

  • Permission denied after Upload Image

    Hi Chaps,

    I have a script to upload image that works on my Apache on the server development IIS, but the Apache Lunix server, although the images are downloaded properly and the MySQL database is updated correctly, I can't see the images.

    Viewing the HTML source code, check the FTP files and database values, all look OK.

    But the picture does not show, just the white box with the Red Cross in the corner.

    If I try to copy the shortcut from the image and open it in a separate window, I get the following:

    Quote:
    bans that have permission to access [path to image]

    I'm not sure what to try next, it seems strange that the source/database / files look good but it just will not appear!



    I tried both $HTTP_POST_FILES and $_FILES to download images, but both have the same result.

    If anyone has any ideas, please help!

    Have you checked the file permissions?

  • CiscoSecure ACS RADIUS logs upload on FTP Server v4.2

    Hello

    I use an appliance v4.2 CiscoSecure ACS, in this sort as RADIUS logs upload on FTP server because it has limitation for storing RADIUS logs.

    Please advice.

    Thank you

    AS

    You can only configure logging remotely. The Cisco Secure ACS Solution engine devices configured to use remote agent send the record directly on the logging of remote agent service, CSLogAgent data. CSLogAgent wrote logging hard disk data to the location specified by the configuration provider. The logs contain the columns specified by the configuration provider.

    http://www.Cisco.com/en/us/docs/net_mgmt/cisco_secure_access_control_server_for_windows/4.2/user/guide/LgsRpts.html#wp703058

    Jatin kone
    -Does the rate of useful messages-

  • Is it possible to see the names of the places for the uploaded images of office?

    I downloaded several collections of images Fund (lightning, moon, scenery, etc.), but cannot see where these images are taken.  My office of Bing puts a new picture every day and I can move my cursor over the "i" zone and see where he is.  Is anyway to do this with the uploaded images?

    Thank you!

    Hello

    Thank you for contacting Microsoft Answers.

    Details of the images found in the Details tab of the image properties. If you do not see such a thing, you cannot find the location without the support of the photographer.

    Usually, these days, cameras equipped with GPS are available. They will download the information of location automatically, if the option is enabled, and you can easily find the location, according to the coordinates.

  • I opened one of my projects of recorded video but all uploaded images display a message red screen "Media disconnected". What is the cause?

    I opened one of my projects of recorded video but all uploaded images display a message red screen "Media disconnected". What is the cause?

    Download means to transfer data from the internet to the computer.

    If you double-click the file missing in the assets of the project, it will open a window saying where is so and so file.

    Navigate to the file and click OK.

    The rest of the files could follow, perhaps brought to them all separately.

  • I have recently subscribed to Adobe cc and chose a price option that offers access to 10 pictures per month since Adobe Stock. I've never uploaded images, but now I'm trying to download something, and system wonder an awards page. Can anyone help

    I have recently subscribed to Adobe cc and chose a price option that offers access to 10 pictures per month since Adobe Stock. I've never uploaded images, but now I'm trying to download something, and system wonder an awards page. Can anyone help?

    Hello Helena

    When you sign in to stock.adobe.com with your Adobe ID, please make sure that you select the account of the company rather than the personal account and you should see the distribution of your image:

    Thank you

    Bev

  • Allow a user to the admin of the site and upload images to a DB if possible (was: new to Muse...)

    I've been a user of Dreamweaver, at the time of UltraDev, I need to be able to allow a user to the admin of the site and upload images to a DB if possible. For this I used in DW with a DB on the backend. The customer, log in and then upload images and Add info to the image and details.

    Then I looked and did not find anything which allows for a DB on the backend... can someone help with this question?

    Thank you

    B

    Thanks for the info... I think that allowing them to edit via the adobe software in the edition of browser will do.
    https://www.YouTube.com/watch?v=p12weA0YMCc

    Best regards

    B

  • Update of Muse CC 2014.3 still have FTP upload problem: the server responding is not in time, FTP is not supported on this server [connection has expired after 15001 millseconds.] I have no problem with CC 2014. Can you suggest what I should do?

    Update of Muse CC 2014.3 still have FTP upload problem: the server responding is not in time, FTP is not supported on this server [connection has expired after 15001 millseconds.] I have no problem with CC 2014. Can you suggest what I should do?

    Hello.

    Today, I had the opportunity to work with a user of Muse with the same problem after you perform the troubleshooting steps in the post above we decided to communicate with the host.

    Later, I learned to know that host IP of the user of Muse and they managed to unlock and muse began to connect to the FTP host.

    I have another host scenario suggests Muse to add user : 21 to the FTP address and then Muse was able to connect.

    For example ftp.domain.com:21

    Please try the suggestion 2 above and let me know if it works.

    Concerning

    Vivek

  • With the help of AUSST - latest updates of Adobe CC 2014 are not uploaded to the server - how to solve this problem?

    With the help of AUSST - latest updates of Adobe CC 2014 are not uploaded to the server - how to solve this problem?

    I tried both incremental and train to do a fresh install (. / AdobeUpdateServerSetupTool - root = "/ serverroot/updates / Adobe / CS '-fee)

    If anyone can answer this - please let me know.

    Hi Mark,

    Try to refresh the web server and run the AUSST with cool switch. In addition, please make sure that you have enough disk space available in the location of the server.

    Thank you

    Ashish

  • I can't delete some files that I uploaded to the server. What should I do?

    I can't delete some files that I uploaded to the server. I get a notice: FTP an error occurred - cannot delete the PDF download server folder. Operation failed. The directory is not empty, or there may be a permission problem.

    What should I do?

    Try to delete the files in your folder first.

    If there is a permissions problem on the server that you cannot delete files, you need to contact your Site Administrator (if you have one) or your Web hosting provider.

    Nancy O.

  • Voiceover plays not once uploaded to the server

    I have a voiceover in animation that is triggered by a button my film. He plays very well locally but once all files are uploaded to a server, it does not play. I use mp3 and ogg formats. I have two other sound effects that are the same size and are treated in the same way that work very well.

    It's working now! Turned out be the way which I wondering the promotion of the file... typical user :-) error

    Thank you!

  • Lack of Upload Image button

    I don't see my icon to upload image button. If I open a blank document, I see. Then when I go back to my original file disappears. I can not adjust the size of the menu or switch. He just disappeared. Does anyone know how to fix this?

    I tried to clear my cache, restart Captivate, restart my machine, except with respect to a new type of document.

    I am using Captivate cs5.5 for OSX (Lion)

    I'd like to show you a picture but my proxy won't let me download a

    Take a look at the answer in this recent thread:

    http://forums.Adobe.com/message/4463187#4463187

  • Get the SIGSEGV segmentation fault when I upload images to the server

    I am gettting segmenation error when I tried to download images. I followed the link to download the images on the server http://blackberry.github.io/Cascades-Samples/imageloader.html . When I tried to download more images (for examples of 200 images) of the server I got the message as (/ base/usr/lib/qt4/lib/libQtCore.so.4.8.4@_ZN27QEventDispatcherUNIXPrivate8doSelectE6QFlagsIN10QEventLoop17ProcessEventsFlagEEP7timeval+0x11f) = 001313c mapaddr 8. REF = 00000011 bdslot is 1 error. using the above code example, I get the same problem. Please suggest me the best approach for this problem. I found that the problem with QnetworkaccessManager.

    It is very difficult to debug the application, given that the code is run from the qml. In addition, QnetworkManager basic network communication is asynchronous. the problem is mainly due to the network manager's response signal. When I try to run at a given time, I get signal mishandling by the network manager, which leads to a segmentation (which happens in image asynchronous download). now, I changed it to synchronized image download approach resloved my problem, but with little performance considerations.

    Thanks for the reply.

    Mercy lipatoff

Maybe you are looking for

  • Reentrant PtbyPt increment

    Under the heading other PtbyPt functions, we increment Ptby Pt and decrement, PtbyPt.  Real estate execution VI, reentrancy is set to Preallocated incoming clone of execution.  Does this mean I can use VI to count several things? If this VI can be us

  • Why nothing will solve my Vista Service Pack E_FAIL(0x80004005) error?

    I try to install sp2 to vista on my 32-bit operating system, but every time I have to try works very well until is restarts, and then to move on to step 3 of 3 100% and then goes to the service pack do not have install, reverting changes when that wa

  • B210a

    Aloha: I have B210a, all-in-one, which worked fine for months.  It can be hung on my Mac (OS 10.6.8) using USB or wifi. No reason it just stopped working. I stopped for a long time and pulled the powr Plug and the USB socket. When I came back, I star

  • Smartphones blackBerry email setup

    I'm unable to access the functionality of under Setup e-mail accounts. Is there a place to enable the feature. When I click on it using the scroll of the system does not start. Curve 9300 BlackBerry. Thank you. Jaz.

  • I'm not going to create a website of colorfull, but I confused with the color combinations?

    Please suggest the best sets of colors coporarte