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
Contributor
amitgaur06
Posts: 20
Registered: ‎09-06-2011
My Device: torch
Accepted Solution

Getting exceptions when uploading a file from blackberry

I have implemented File Upload(basically a photo upload) from blackberry to my jboss server.

I wanted to use the phonegap apis to upload the file but it has a limitation.(though phonegap has many)

It requires the full path of the file which we can't get from a form file field. (Only file name is accessible)

Also, its example is also very poor as it uploads only the files whose paths are known.

 

So I used a simple form submit with multipart/form-data request and following is the client side code:

 

function uploadProfilePicToServer(){
    parent.pop.popOut("Loading...");
    var xhrObj = false;
    var self = this;
  
    var file = document.getElementById("ppic");
    file = file.files[0];
    xhrObj = new XMLHttpRequest(); 
    try{
       
     
        xhrObj.open("POST", URL + "service", true); 
        xhrObj.setRequestHeader("Content-type", "multipart/form-data");
        xhrObj.onreadystatechange = function() {
            if (xhrObj.readyState == 4&&xhrObj.status == 200) {
                alert(xhrObj.responseText);
            }
        }
        var formData = new FormData();
       
        formData.append("cfs", "imgup");
        formData.append("cfa", "pi");
        formData.append("ppic", file);
       
        xhrObj.send(formData);
    }catch(e){
        alert(e.message);
    }
}

 

 

I have used Apache commons FileUpload library on the server side.(the one shown in their doc)

Also, have set the maxsize and timeout params correctly.

 

 

Problems that are coming on intranet

When using in intranet, for smaller sizes like 50-100KB it works correctly, but for larger files i.e. >500KB, I am getting following exception on server:

 

2011-09-23 10:49:10,640 ERROR [http-127.0.0.1-8080-2] [com.spidoss.cityfan.controller.CityFanController:89] org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly

 

 

Problems that are coming on internet

When I use an external server to upload the files, I keeps on getting the above exception.

 

I thought of building an extension for file upload, but Java also requires fully qualified path of the file and we can't get it from the javascript :No:

Has anyone have ever achieved uploading a file to an external server with BrowserField?

Please help.

Retired
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Getting exceptions when uploading a file from blackberry

You can retrieve a fully qualified local path of a file using our File IO APIs

 

http://www.blackberry.com/developers/docs/webworks/api/blackberry.io.file.html

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Contributor
amitgaur06
Posts: 20
Registered: ‎09-06-2011
My Device: torch

Re: Getting exceptions when uploading a file from blackberry

Hi Tim,

 

Thanks for your reply. But my problem is when i use file input field it only gives me file name.

file I/O apis only provides services to known paths and not dynamically selected path. Please correct me if I am wrong.


Thanks

Retired
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Getting exceptions when uploading a file from blackberry

If you want to prompt your user to pick a file you can also use the Community File Picker extension

 

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

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Contributor
amitgaur06
Posts: 20
Registered: ‎09-06-2011
My Device: torch

Re: Getting exceptions when uploading a file from blackberry

 
Contributor
amitgaur06
Posts: 20
Registered: ‎09-06-2011
My Device: torch

Re: Getting exceptions when uploading a file from blackberry

While building my application following error occured

C:\Documents and Settings\anand\Local Settings\Temp\widgetGen.4683360291316794484665.tmp\blackberry\web\widget\autogen\WidgetConfigAutoGen.java:27: package blackberry.ui.file does not exist
        _widgetExtensions.addElement(new blackberry.ui.file.FilePickerExtension());

 

Please help.

Retired
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Getting exceptions when uploading a file from blackberry

We just had a post the other day around this.. my guess is that you have the same issue that they did.. 

 

Double check that your file paths are exactly like they are specified in step (6) of the instructions... the other developer forgot the "src" directory

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Contributor
amitgaur06
Posts: 20
Registered: ‎09-06-2011
My Device: torch

Re: Getting exceptions when uploading a file from blackberry

Thanks Tim,

It worked like a charm and I am now getting the file with complete.

Also, I will let you know when I am finished with this :smileyhappy:

Thanks a ton.

 

Contributor
amitgaur06
Posts: 20
Registered: ‎09-06-2011
My Device: torch

Re: Getting exceptions when uploading a file from blackberry

Hi Tim,

 

FilePicker is not working on the device though it worked perfectly on Simulator.

I checked the device logs and they are showing following eror logs

Please help

 

Name: Error
GUID: 9c3cd62e3320b498
Time: Sep 24, 2011 16:58:20
No detail message
net_rim_cldc(4C94D16C)
 ControlledAccess
 assertRRISignatures
 0x3B82
net_rim_cldc_io_remotefile(

4C94D5D5)
 NetworkFileCacheManager
 getInstance
 0x207D
net_rim_cldc_io_remotefile(4C94D5D5)
 NetworkFileConnection
 <clinit>
 0x38A8
net_rim_bb_file_explorer_library-6(4C94D68E)
 FileSystemExploreManager
 <init>
 0x1674
net_rim_bb_file_explorer_library-6(4C94D68E)
 FileSystemExploreManager
 <init>
 0x15F0
net_rim_bb_file_explorer_library-1(4C94D68E)
 DocumentExploreScreen
 <init>
 0x3B03
net_rim_bb_file_explorer_library-6(4C94D68E)
 FileSelectionVerb$ScreenProvider
 createContextScreen
 0x91B
net_rim_bb_file_explorer_library-6(4C94D68E)
 FileSelectionVerb$ScreenProvider
 getContextScreen
 0xA8B
net_rim_bb_file_explorer_library-3(4C94D68E)
 FileSelectionVerb
 invoke
 0x525
net_rim_bb_apps_framework(4C94D62E)
 FileSelector
 <private>
 0x3B7A
net_rim_bb_apps_framework(4C94D62E)
 FileSelector
 selectFile
 0x3A2E
net_rim_bb_file_explorer_library-5(4C94D68E)
 FilePickerImpl
 show
 0x6697
CityBraid-1(4E7DBD08)
 FunctionOpenPicker$1
 run
 0x2252
net_rim_cldc-9(4C94D16C)
 Application
 dispatchInvokeLater
 0x1B76
net_rim_cldc-9(4C94D16C)
 Application
 <private>
 0x2AB4
net_rim_cldc-9(4C94D16C)
 Application
 processNextMessage
 0x1BEA
net_rim_cldc-9(4C94D16C)
 Application
 enterEventDispatcher
 0x1B01
CityBraid-1(4E7DBD08)
 Widget
 main
 0x68BF



Contributor
amitgaur06
Posts: 20
Registered: ‎09-06-2011
My Device: torch

Re: Getting exceptions when uploading a file from blackberry

Hi Tim,

 

Exception on device side has now changed to following. Please have a look

 

Name: NoClassDefFoundError
GUID: 9c3cd62e3320b498
Time: Sep 24, 2011 20:09:42
No detail message
net_rim_bb_file_explorer_

library-6(4C94D68E)
 FileSystemExploreManager
 <init>
 0x1677
net_rim_bb_file_explorer_library-6(4C94D68E)
 FileSystemExploreManager
 <init>
 0x15F0
net_rim_bb_file_explorer_library-1(4C94D68E)
 DocumentExploreScreen
 <init>
 0x3B03
net_rim_bb_file_explorer_library-6(4C94D68E)
 FileSelectionVerb$ScreenProvider
 createContextScreen
 0x91B
net_rim_bb_file_explorer_library-6(4C94D68E)
 FileSelectionVerb$ScreenProvider
 getContextScreen
 0xA8B
net_rim_bb_file_explorer_library-3(4C94D68E)
 FileSelectionVerb
 invoke
 0x525
net_rim_bb_apps_framework(4C94D62E)
 FileSelector
 <private>
 0x3B7A
net_rim_bb_apps_framework(4C94D62E)
 FileSelector
 selectFile
 0x3A2E
net_rim_bb_file_explorer_library-5(4C94D68E)
 FilePickerImpl
 show
 0x6697
CityBraid-1(4E7DE908)
 FunctionOpenPicker$1
 run
 0x2252
net_rim_cldc-9(4C94D16C)
 Application
 dispatchInvokeLater
 0x1B76
net_rim_cldc-9(4C94D16C)
 Application
 <private>
 0x2AB4
net_rim_cldc-9(4C94D16C)
 Application
 processNextMessage
 0x1BEA
net_rim_cldc-9(4C94D16C)
 Application
 enterEventDispatcher
 0x1B01
CityBraid-1(4E7DE908)
 Widget
 main
 0x68BF