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

Java Development

Reply
New Developer
Posts: 23
Registered: ‎01-21-2010
My Device: A
My Carrier: A

Upload image/video/audio to web service???

Hi

 

I am creating an application that will allow the user to upload images/video/audio to a server!

 

The only thing I have found is this post.

 

Currently I am trying to upload an image to a web service, but want to be able to upload video and audio!

 

The service accepts a string (byte array) and converts it to an image.

 

How do I convert an image to a byte array so that the web service will accept it?

 

Is a web service the best way to go?

 

Thanks

Developer
Posts: 455
Registered: ‎01-14-2009
My Device: Apple iPhone 3GS 16GB

Re: Upload image/video/audio to web service???

 

  public byte[] getByteArray() throws FileNotExistsException, Exception {
            try
            {
                 
                if (fc == null) {
                        fc = (FileConnection) Connector.open("filelocation",
                                        Connector.READ_WRITE);
                        if (!fc.exists())
                                throw new FileNotExistsException("Can't open requested file :");
                }
                
                _inputstream = fc.openInputStream(); 
                int x;
                BAOS = new ByteArrayOutputStream();
                while ((x = _inputstream.read()) != -1) {
                        BAOS.write((byte) x);
                } 
        }
        catch(Exception e)
        {
            
        }  
                return BAOS.toByteArray();  
        }

 

 

Developer
Posts: 455
Registered: ‎01-14-2009
My Device: Apple iPhone 3GS 16GB

Re: Upload image/video/audio to web service???

Try this and let me know the output.!!!!!!!!!!!!!

Regular Contributor
Posts: 61
Registered: ‎11-08-2010
My Device: Not Specified

Re: Upload image/video/audio to web service???

Hi,

      Can you please send me a link which will be helpfull for me in uploading my video to the server...

 

With Regards

Sunil

Developer
Posts: 455
Registered: ‎01-14-2009
My Device: Apple iPhone 3GS 16GB

Re: Upload image/video/audio to web service???

Open a connection with your server, Use the above method to get the byte array and then write it to the outputstream .