Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Visitor
Think_Done
Posts: 1
Registered: ‎12-27-2011
My Device: 8300
My Carrier: NONE

File Upload Black berry

**i am using the <h1>below code for uploading file (php + java code). but it’s not uploading.</h1>**

       

        1. file is present in card(simulator) i check it via file explorer demo .

        2. i tried to write text file when it hit the page but it’s not writing.

        3. I have taken the code of file upload from another site. But can’t able to use .

       

        So please share any code or remove error from the bellow code.

 Thanks in advance

       

       

       

       

    /******************Black Berry  Java Code ******************/

    package mypackage;

   

    import java.io.IOException;

    import java.io.InputStream;

    import java.io.OutputStream;

    import javax.microedition.io.Connector;

    import javax.microedition.io.HttpConnection;

    import javax.microedition.io.file.FileConnection;

    import net.rim.device.api.ui.UiApplication;

    import net.rim.device.api.ui.container.MainScreen;

   

    public final class MyScreen extends MainScreen

    {

    public MyScreen() throws IOException

    {  

    synchronized (UiApplication.getEventLock()) {

    uplaod_file();

    }

    }

    public void uplaod_file() throws IOException{

    HttpConnection httpConn = (HttpConnection) Connector.open("http://localhost/upload/upload_file.php");//file

    FileConnection fileConn = (FileConnection) Connector.open("file:///SDCard/n.txt");

    InputStream in = fileConn.openInputStream();

    OutputStream out = httpConn.openOutputStream();

    byte[] buffer = new byte[1000];

    int bytesRead = 0;

    bytesRead=in.read(buffer);

    while((bytesRead) > 0)

    {

    out.write(buffer, 0, bytesRead);

    }

    }

    }

       

        /****************** Php code****************** /

        <?php

          if ($_FILES["file"]["error"] > 0)

        {

        echo "Return Code: " . $_FILES["file"]["error"] . "<br />";

        }

        else

          {

        /*-File writeing check*/

        $myFile = "testFile.txt";

        $fh = fopen($myFile, 'w') or die("can't open file");

        fwrite($fh, "that");

        fclose($fh);

       

         echo "Upload: " . $_FILES["file"]["name"] . "<br />";

         echo "Type: " . $_FILES["file"]["type"] . "<br />";

         echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";

         echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

       

         if (file_exists("upload/" . $_FILES["file"]["name"]))

         {

         echo $_FILES["file"]["name"] . " already exists. ";

         }

        else

         {

         move_uploaded_file($_FILES["file"]["tmp_name"],

         "upload/" . $_FILES["file"]["name"]);

         echo "Stored in: " . "upload/" . $_FILES["file"]["name"];

         }

        }

        ?>

 

Please use plain text.
New Developer
UserNeo
Posts: 74
Registered: ‎10-23-2008
My Device: 9000

Re: File Upload Black berry

Hi,

 

maybe you testing the Extension "FileUpload" from github?

https://github.com/blackberry/WebWorks-Community-APIs/tree/master/Smartphone/FileUploader 

 

cu

UserNeo 

Please use plain text.