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
misterza
Posts: 19
Registered: ‎06-28-2010
My Device: n/a
My Carrier: n/a

Upload file from widget

Hi all,

 

Does anybody have an example of how to upload a file from a widget to an asp.net server?

 

Thanks

Please use plain text.
BlackBerry Development Advisor
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Upload file from widget

Have you tried doing something like the following?

 

http://support.microsoft.com/kb/323245

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
Contributor
misterza
Posts: 19
Registered: ‎06-28-2010
My Device: n/a
My Carrier: n/a

Re: Upload file from widget

I have a button which invokes the camera, and then uses the file IO classes to find the last image taken. But then I can't work out how to upload the file to the server.

 

I thought I could just use a file upload form, but I can't set the upload source using javascript.

Please use plain text.
BlackBerry Development Advisor
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Upload file from widget

So you have the file path and you set the value of the <form> <input> via JavaScript but it is not properly getting set?

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
Contributor
misterza
Posts: 19
Registered: ‎06-28-2010
My Device: n/a
My Carrier: n/a

Re: Upload file from widget

Hi Tim,

 

Yes I tried setting the value of the file form input but it is not getting set. Apparently on a normal browser setting the value of a file input control is not allowed as it is a security risk.

 

Is this allowed on BlackBerry? Or are we supposed to use another approach?

 

Code:

 

    var i;
    var root = "file:///store/home/user/pictures/";
    
    var files = blackberry.io.dir.listFiles(root);
    var newestDate = new Date(0);
    var newestFile;
        
    for (i = 0; i < files.length; i++) {
    var properties = blackberry.io.file.getFileProperties(root + files[i]);
    fileDate = properties.dateCreated;
    if (fileDate > newestDate) {
        newestDate = fileDate;
        newestFile = files[i];
        }    
    }

   document.getElementById("FileUpload1").value = newestFile;

Please use plain text.
Visitor
misteff25
Posts: 1
Registered: ‎08-11-2010
My Device: Not Specified

Re: Upload file from widget

Forgive me if I'm missing something here.  Was this questions answered?  Does it work to set the value of the form input via JS or is it not allowed?  If its not allowed what is the other approach?

 

Thanks!

Please use plain text.
New Contributor
reihead
Posts: 2
Registered: ‎11-01-2010
My Device: Not Specified

Re: Upload file from widget

Any update about this problem?

Does the JS set works?

 

Thanks in advance

Please use plain text.
Contributor
misterza
Posts: 19
Registered: ‎06-28-2010
My Device: n/a
My Carrier: n/a

Re: Upload file from widget

No it didnt work.

Please use plain text.
Contributor
mobabelsupport
Posts: 21
Registered: ‎11-24-2010
My Device: Not Specified
My Carrier: T-com

Re: Upload file from widget

i have same problem here, upload file in form and set the value for file, and call submit, but server did not receive the file, the incoming data is  0 byte

 

Please use plain text.
BlackBerry Development Advisor
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Upload file from widget

[ Edited ]

From what I understand... the spec for the standard says that you cannot change the file path in the input element via JavaScript.. it must be set by using a file browse dialog.  This way JavaScript cannot arbitrarily upload a file from your system... 

 

 

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.