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
New Developer
yadavtarun03
Posts: 7
Registered: ‎11-28-2009
My Device: Not Specified

Redirecting to local HTML pages and POSTing from iframes

I'm using the Eclipse bundled with the installer from http://na.blackberry.com/eng/developers/browserdev/eclipse.jsp The simulator reports that it is BlackBerry Smartphone Simulator 2.13.0.56

 

Background to what I'm trying to do:

1. Upload an image to the server for processing

2. Wait for the result - I plan to use the push infrastructure for this

 

 


 

A. Unable to POST from an iframe

I was trying to upload the file by faking an AJAX upload by using a hidden iframe to upload. However, when I use something like

 

 

<form action="http://<host>.dyndns.biz:8080/App/servlet" method="post" enctype="multipart/form-data" target="upload_target">
File: <input name="myfile" type="file" />
<input type="submit" name="submitBtn" value="Upload" />
</form>
<iframe id="upload_target" name="upload_target" src="#" style="width:0;height:0;border:0px solid #fff;"></iframe>
</body>

 

The server never gets a request. This works within my browser (Firefox 3.5.5). My config.xml has the entry for dyndns.biz which I'm using for Dynamic DNS to make a roundtrip and access my local machine over the Internet

<access subdomains="true" uri="http://dyndns.biz"/>

 

I then tried to use an iframe that loaded the upload form and then was hidden on submit:

 

 

index.html:
<head>
<script type="text/javascript">
 function hideUpload()
 {
	 document.getElementById("uploader").setAttribute("class", "invisible");
 }
</head>

<body>
<iframe id="uploader" src="inner.html" class="not-invisible"></iframe>
</body>

inner.html

<form action="http://<host>.dyndns.biz:8080/App/servlet"
	method="post" enctype="multipart/form-data"
	id="file_upload_form_no" onSubmit="window.top.window.hideUpload();">File: <input name="myfile" type="file" />
<input type="submit" name="submitBtn" value="Visible Upload"/></form>

 

 

However, this results in a GET request to the servlet and the file isn't uploaded.

 

As a workaround, I tried what I've listed below, but that doesn't seem to work either

 

 


 

 

B. Unable to redirect to "local://" pages or invoke BlackBerry Widget APIs from a page served by the server

 

I thought I'd try getting around the problems mentioned in A above by trying this:

1. Upload file to server

2. Have the server send back a page custom built for the BlackBerry with something like

 

<script>
function subscribe() {
		// open the listener to listen if there is pushed data coming through
	blackberry.push.openPushListener(handleReturnData, port);
	alert("push listening has started");
}
</script>
</head>
<body onload="subscribe();">
</body>

 But it appears that the device will not allow use of the BlackBerry API from a non-local resource

 

I then tried redirecting to a local page where the subscription for push notifications could be made:

 

 

<script>
function redirect() {
    window.location = "local://push.html";
}
</script>
</head>
<body onload="redirect();">
</body>

 

 But this throws up a dialog that reads "No host should be specified in the local: protocol"

 

I get the same thing when the page sent by the server has a link with href="local://push.html".

 

So how can I redirect from a server's page to my widget's pages?

 

 


 

 

So, to sum up:

 

My goal is to Upload a file to the server and have the app listen for a response which it will the parse.

My understanding is that to do this would require something like an AJAX file upload. But AJAX doesn't really have file uploads and it's faked by using hidden iframes. But that doesn't seem to work.

 

In that case, pointers on how to redirect from a page that was sent by server, to a widget's local page would also help in working around these limitations.

 

Thanks!

 

Please use plain text.
New Developer
yadavtarun03
Posts: 7
Registered: ‎11-28-2009
My Device: Not Specified

Re: Redirecting to local HTML pages and POSTing from iframes

Argh! Came across http://supportforums.blackberry.com/t5/Web-Development/Widget-Navigation/td-p/378511 and realized I was using only two slashes in my URL instead of 3. Once i fixed that, it works as expected.

 

I still wonder why a POST from an iframe gets converted into a GET on the serverl

Please use plain text.
New Developer
Ultima
Posts: 5
Registered: ‎11-06-2009
My Device: Not Specified

Re: Redirecting to local HTML pages and POSTing from iframes

Regarding POSTing forms to IFRAMEs, I can definitely confirm. In fact, I reported this exact issue almost 2 months ago with nary a reply to confirm or deny the problem. It began happening with BlackBerry OS v5.0.

 

We need to somehow get this bug to the devs' attentions more prominently, as this technique is very commonly used in AJAX applications.

Please use plain text.
BlackBerry Development Advisor (Retired)
astanley
Posts: 1,382
Registered: ‎07-02-2009
My Device: BlackBerry Bold 9900
My Carrier: Bell

Re: Redirecting to local HTML pages and POSTing from iframes

Ultima - thanks for your post.

 

Would you please submit a defect for this in our online Developer Issue Tracker system?

 

That will allow us to more easily escalate this issue for investigation to the proper development team.

 

Sincerely,

Adam

Follow me on Twitter: @n_adam_stanley
-------------------------------------------------------------------------------------------------------------------------
Your app doesn't work? Use BlackBerry remote web inspector to find out why.
Please use plain text.
New Developer
Ultima
Posts: 5
Registered: ‎11-06-2009
My Device: Not Specified

Re: Redirecting to local HTML pages and POSTing from iframes

[ Edited ]

Alright, done (see ticket #WEBAPI-33).

 

Apologies for selecting an unaffected version -- I wouldn't have been able to create the ticket otherwise, as the form required a version to be selected among choices that did NOT include the actual affected version (5.0), and only listed up to v4.7.0 (which I selected). That is, when I tried submitting the ticket with Version set to Unknown, the form validator complained about an invalid version being submitted.

Please use plain text.
BlackBerry Development Advisor (Retired)
astanley
Posts: 1,382
Registered: ‎07-02-2009
My Device: BlackBerry Bold 9900
My Carrier: Bell

Re: Redirecting to local HTML pages and POSTing from iframes

In regards to the original posting, the access element added to your config.xml document should also include the port number of your dynnds.biz URL (since you are using the port in the form action), such as this:

 

 

 

<access subdomains="true" uri="http://dyndns.biz:8080"/>

 

 

Can you verify whether you also made that change?

 

 

To confirm your issue regarding redirecting to an embedded resource page, yes in order to use the "local" protocol, it must be followed by three forward slashes: "local:///".  This is similar to accessing files from the local file system, or removable media (e.g. "file:///SDCard").

 

 

Best wishes,

Adam

 

Follow me on Twitter: @n_adam_stanley
-------------------------------------------------------------------------------------------------------------------------
Your app doesn't work? Use BlackBerry remote web inspector to find out why.
Please use plain text.
New Contributor
rakesh_katkam2012
Posts: 6
Registered: ‎11-28-2012
My Device: Torch 9800
My Carrier: Docomo

Re: Redirecting to local HTML pages and POSTing from iframes

I am also facing same issue.I am using blackberry webworks. I want to redirect to local page from the server page. I tried following code : window.location = 'local:///index.html';

But this isnt working.

please help !!

Please use plain text.