Software Archive
Read-only legacy content
17061 Discussions

Cannot upload from mobile

ben4
Beginner
434 Views

Hello,

 

I am using the plugin "InAppBrowser" from Cordova, I am passing in a url from my website, the page is showing fine but when I try to upload something on my website, the upload popups are not showing up in the mobile but when accessed from the website, it works fine.

 

It is a sinple html input field as:

<input id="upload1" type="file" value="" name="coverimage[]" /></div>

 

Any idea why it does not work? It looks like the popups are blocked.

 

Here is my code:

 

        <script type="text/javascript" charset="utf-8">
            // Wait for device API libraries to load
            //
            document.addEventListener("deviceready", onDeviceReady, false);
        
            // device APIs are available
            //
            function onDeviceReady() {
                 var ref = window.open('https://website.com', '_blank', 'location=yes');
                 //ref.addEventListener('loadstart', function(event) { alert('start: ' + event.url); });
                 //ref.addEventListener('loadstop', function(event) { alert('stop: ' + event.url); });
                 //ref.addEventListener('loaderror', function(event) { alert('error: ' + event.message); });
                 //ref.addEventListener('exit', function(event) { alert(event.type); });
            }
        </script>

 

 

Thank you for your help,

 

 

Ben

0 Kudos
5 Replies
PaulF_IntelCorp
Employee
434 Views

Your mobile app is not being served by your web site, you have to actually put together a RESTful API to talk to your web site and use AJAX to send files to your server. See this article for some explanation > https://www.raymondcamden.com/2012/05/05/converting-a-dynamic-web-site-to-a-phonegap-application/ < written by a longtime PhoneGap and Cordova developer.

0 Kudos
ben4
Beginner
434 Views

I see, but even if the website is framed inside an iframe in the mobile app?

I am not understanding this part.....

0 Kudos
PaulF_IntelCorp
Employee
434 Views

You mobile device does not have the same freedoms as the browser on your desktop or laptop. For security and privacy reasons, apps have very restricted access to the mobile filesystem. You cannot treat a mobile app like a web site, it's not the same thing. In addition, apps that are simply pointers to web sites tend to get very low ratings and are banned from some stores. Your app should be something that works with your site, not just a simple mirror of your site, for that you can add a desktop icon to simply open your site in the device browser.

Cordova apps use HTML5 to create apps, so it is a way to use your HTML5 programming skills to write an app. It is not a mechanism to simply wrap up a web site in an app. Hope that helps.

0 Kudos
ben4
Beginner
434 Views

Hi Paul,

 

Thank you for the reply. I now understand the security reasons.

I do program in PHP, not at an expert level but well enough to build front and backends. I would like to know something please, lets say I build an app in html5 that requires a login into my website database(mysql), how complicated would it be please?

How can the server on my website can communicate via PHP with the android app for example?

 

Thank you,

 

Ben

0 Kudos
PaulF_IntelCorp
Employee
434 Views

Everything should be done via a RESTful API. You cannot include PHP scripts either embedded or as explicit files in your app; because your app pages are not being "served" by a web site there is no PHP server to interpret them, and there is no "hard connection" between your web site and your app, they are really independent entities.

Login is a difficult thing, you might want to consider adding something like OAuth2 to your web server for login, since there are lots of good Cordova plugins to work with that authentication.

0 Kudos
Reply