Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Input type = "file" button disabled in ICS / Phonegap 2.2
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  17 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Mike Britton  
View profile  
 More options Dec 19 2012, 8:40 pm
From: Mike Britton <mbritto...@gmail.com>
Date: Wed, 19 Dec 2012 17:40:21 -0800 (PST)
Local: Wed, Dec 19 2012 8:40 pm
Subject: Input type = "file" button disabled in ICS / Phonegap 2.2

I need an input type=file web form element to open the file browser and
return to the code with the selected file to be submitted.  I accomplished
this in a standard web form and tested in Android's regular browser, but
when I wrap the app with Phonegap the button no longer works.

What is the workaround for this?  It seems like a lot of people are passing
around an example where the camera is used, but I don't need the camera, I
need a file browser.

Thanks in advance!!

Mike


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike Britton  
View profile  
 More options Dec 21 2012, 3:35 pm
From: Mike Britton <mbritto...@gmail.com>
Date: Fri, 21 Dec 2012 12:35:05 -0800 (PST)
Local: Fri, Dec 21 2012 3:35 pm
Subject: Re: Input type = "file" button disabled in ICS / Phonegap 2.2

/*
       Licensed to the Apache Software Foundation (ASF) under one
       or more contributor license agreements.  See the NOTICE file
       distributed with this work for additional information
       regarding copyright ownership.  The ASF licenses this file
       to you under the Apache License, Version 2.0 (the
       "License"); you may not use this file except in compliance
       with the License.  You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

       Unless required by applicable law or agreed to in writing,
       software distributed under the License is distributed on an
       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
       KIND, either express or implied.  See the License for the
       specific language governing permissions and limitations
       under the License.
 */

package com.ggv.GGVAndroidWrapper;

import android.app.Activity;
import android.os.Bundle;
import org.apache.cordova.*;
import org.apache.cordova.api.*;

import android.util.Log;
import android.webkit.ValueCallback;
import android.widget.Toast;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;

public class GGVAndroidWrapper extends DroidGap
{
 private ValueCallback<Uri> mUploadMessage;
    private final static int FILECHOOSER_RESULTCODE = 1;
    private FileAttachmentChromeClient chromeClient;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        super.loadUrl("http://SOME_EXTERNAL_HTML?8");

        this.chromeClient = new FileAttachmentChromeClient(this,
this.appView);
        this.appView.setWebChromeClient(this.chromeClient);

    }

@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent intent) {
 if (requestCode == FILECHOOSER_RESULTCODE) {
     Context context = getApplicationContext();
     CharSequence text = "requestCode: "+requestCode;
     int duration = Toast.LENGTH_SHORT;

     Toast toast = Toast.makeText(context, text, duration);
     toast.show();

        }
 super.onActivityResult(requestCode, resultCode, intent);

}

    public class FileAttachmentChromeClient extends CordovaChromeClient {

        public FileAttachmentChromeClient(CordovaInterface ctx,
CordovaWebView app) {
            super(ctx, app);

        }

        // For Android > 3.x
        public void openFileChooser(ValueCallback<Uri> uploadMsg, String
acceptType) {

        // Here's where we take over for file uploads.

        // Send intent to open file chooser
            mUploadMessage = uploadMsg;
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);
            i.addCategory(Intent.CATEGORY_OPENABLE);
            i.setType("image/*");

GGVAndroidWrapper.this.startActivityForResult(Intent.createChooser(i,
"Choose type of attachment"), FILECHOOSER_RESULTCODE);

        }

    }    


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Simon MacDonald  
View profile  
 More options Dec 21 2012, 3:45 pm
From: Simon MacDonald <simon.macdon...@gmail.com>
Date: Fri, 21 Dec 2012 15:45:09 -0500
Local: Fri, Dec 21 2012 3:45 pm
Subject: Re: [PhoneGap] Re: Input type = "file" button disabled in ICS / Phonegap 2.2
Hey Mike,

I've successfully been able to get the file chooser up to pick a file
and when I return the file path to the HTML side it seems to be set
correctly but when I asked for input.value in JavaScript I only get
the file name. Have you been able to get the full path in your HTML?

Simon Mac Donald
http://hi.im/simonmacdonald


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike Britton  
View profile  
 More options Dec 21 2012, 5:26 pm
From: Mike Britton <mbritto...@gmail.com>
Date: Fri, 21 Dec 2012 14:26:13 -0800 (PST)
Local: Fri, Dec 21 2012 5:26 pm
Subject: Re: [PhoneGap] Re: Input type = "file" button disabled in ICS / Phonegap 2.2

Hi Simon.

I'm not even there yet.  My Phonegap WebView loads an external URL I've
whitelisted.  Using the above technique, I can get the chooser via an
Intent, but I can't set focus back on my web form once the file has been
chosen.  Is this something you've achieved?

Thanks in advance if you can show me how you did this :)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Simon MacDonald  
View profile  
 More options Dec 22 2012, 10:05 am
From: Simon MacDonald <simon.macdon...@gmail.com>
Date: Sat, 22 Dec 2012 10:05:55 -0500
Local: Sat, Dec 22 2012 10:05 am
Subject: Re: [PhoneGap] Re: Input type = "file" button disabled in ICS / Phonegap 2.2
I pushed up my code to a branch here:

https://github.com/macdonst/cordova-android/tree/fileinput

It is working pretty good except when I do:

 document.getElementById("fp").value;

where "fp" is the id of the input field of type file I only get the
file name and not the full file path.

Almost there....
Simon Mac Donald
http://hi.im/simonmacdonald


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike Britton  
View profile  
 More options Dec 22 2012, 9:37 pm
From: Mike Britton <mbritto...@gmail.com>
Date: Sat, 22 Dec 2012 18:37:36 -0800 (PST)
Local: Sat, Dec 22 2012 9:37 pm
Subject: Re: [PhoneGap] Re: Input type = "file" button disabled in ICS / Phonegap 2.2

Don't know if this can help you since I've gone the native route for this,
but I wriggled my way into getting the file path, extension and mime type
in onActivityResult(). I could bang Google right now I'm so happy.

This is from a file chooser selection on all openable resources on the SD
card.  I'm passing the path with the start activity intent.

@Override

protected void onActivityResult(int requestCode, int resultCode, Intent
data) {

Log.d("result code: ", " " + resultCode);

 Uri uri = data.getData();

String[] proj = { MediaStore.Images.Media.DATA };

Cursor cursor = getContentResolver().query(uri, proj, null, null, null);

int column_index = cursor

 .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);

cursor.moveToFirst();

Log.d("Complete File Path ", "" + cursor.getString(column_index));

 Intent sharePageIntent = new Intent(this, ShareActivity.class);

sharePageIntent.putExtra(FILE_PATH, cursor.getString(column_index));

startActivity(sharePageIntent);

 super.onActivityResult(requestCode, resultCode, data);

}

I moved away from staying in Cordova, since my HTML is web-based and not
compiled into the application.  I'm not sure, but I don't think it's
possible for a remote web application to do things like call Phonegap
plugins.  If I'm wrong, which I hope I am, at least I'll have this native
piece.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Simon MacDonald  
View profile  
 More options Dec 24 2012, 9:55 am
From: Simon MacDonald <simon.macdon...@gmail.com>
Date: Mon, 24 Dec 2012 09:55:46 -0500
Local: Mon, Dec 24 2012 9:55 am
Subject: Re: [PhoneGap] Re: Input type = "file" button disabled in ICS / Phonegap 2.2
Yeah, I'm in the same boat as you. In onActivityResult I have all the
information I need including the file path, mime type, etc. but when I
call

mUploadMessage.onReceiveValue(result);

in order to update the input tag in the HTML it does not get set
correctly. I need to look into what is happening there a bit more and
see if there is anyway I can update it manually.

Simon Mac Donald
http://hi.im/simonmacdonald


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike Britton  
View profile  
 More options Dec 24 2012, 3:31 pm
From: Mike Britton <mbritto...@gmail.com>
Date: Mon, 24 Dec 2012 12:31:12 -0800 (PST)
Local: Mon, Dec 24 2012 3:31 pm
Subject: Re: [PhoneGap] Re: Input type = "file" button disabled in ICS / Phonegap 2.2

Just as I finished a native version, I got uploads working in WebView.
 Hope this helps.  It's undocumented, strictly speaking.

Java:

package com.ggv.GGVAndroidWrapper;

import java.util.Random;

import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import org.apache.cordova.*;
import org.apache.cordova.api.*;

import android.util.Log;
import android.webkit.ValueCallback;
import android.widget.Toast;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;

public class GGVAndroidWrapper extends DroidGap {

private ValueCallback<Uri> mUploadMessage;
private final static int FILECHOOSER_RESULTCODE = 1;
private FileAttachmentChromeClient chromeClient;

@Override
public void onCreate(Bundle savedInstanceState) {
Random generator = new Random();
int r = generator.nextInt();

super.setBooleanProperty("showTitle", true);

super.onCreate(savedInstanceState);

super.setBooleanProperty("loadInWebView", true);

super.loadUrl("http://path/to/htmlform/file_upload_test.html?"
+ r);

this.chromeClient = new FileAttachmentChromeClient(this, this.appView);
this.appView.setWebChromeClient(this.chromeClient);

}

 @Override
protected void onActivityResult(int requestCode, int resultCode,
Intent intent) {

if (requestCode == FILECHOOSER_RESULTCODE) {
 if (null == mUploadMessage) {
 return;
 }

 Uri result = intent == null || resultCode != RESULT_OK ? null :
intent.getData();
 mUploadMessage.onReceiveValue(result);
 mUploadMessage = null;

Context context = getApplicationContext();
CharSequence text = "requestCode: " + requestCode;
int duration = Toast.LENGTH_SHORT;

Toast toast = Toast.makeText(context, text, duration);
toast.show();

}

super.onActivityResult(requestCode, resultCode, intent);

}

public class FileAttachmentChromeClient extends CordovaChromeClient {

public FileAttachmentChromeClient(CordovaInterface ctx,
CordovaWebView app) {
super(ctx, app);

}

// For Android > 3.x
public void openFileChooser(ValueCallback<Uri> uploadMsg,
String acceptType) {

// Send intent to open file chooser
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("image/*");

GGVAndroidWrapper.this.startActivityForResult(
Intent.createChooser(i, "Choose type of attachment"),
FILECHOOSER_RESULTCODE);

}
}
}

HTML:

<html>

    <head>

        <title>File Upload Test Form</title>

        <script language="JavaScript" src="../js/lib/jquery-1.7.1.min.js"></
script>

    </head>

    <body onload="init()">

        test page for JavaScript / Phonegap connectivity

        <p></p>

        <form method="POST" enctype="multipart/form-data" action=
"http://path/to/script/uploads.php">

        File to upload: <input type="file" name="upload">&nbsp;&nbsp;

        <input type="submit" value="Press to Upload..."> to upload the file!

        </form>                

    </body>

</html>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike Britton  
View profile  
 More options Dec 24 2012, 3:58 pm
From: Mike Britton <mbritto...@gmail.com>
Date: Mon, 24 Dec 2012 12:58:18 -0800 (PST)
Local: Mon, Dec 24 2012 3:58 pm
Subject: Re: [PhoneGap] Re: Input type = "file" button disabled in ICS / Phonegap 2.2

Further clarification:  the solution above is for Android 3.x and above.  It needs to be in DroidGap, IMO.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Simon MacDonald  
View profile  
 More options Dec 24 2012, 4:26 pm
From: Simon MacDonald <simon.macdon...@gmail.com>
Date: Mon, 24 Dec 2012 16:26:12 -0500
Local: Mon, Dec 24 2012 4:26 pm
Subject: Re: [PhoneGap] Re: Input type = "file" button disabled in ICS / Phonegap 2.2

If you look at the branch I posted you'll see I integrated it into
DroidGap/CordovaWebView/CordovaChromeClient. I'm able to get the value back
to the input tag but on 2.x it only gives me the file name while on 3.x+ it
gives me something like this:

12-24 17:17:56.948: D/CordovaLog(4849): result =
C:\fakepath\1352731741721.jpg
12-24 17:17:56.948: D/CordovaLog(4849): files = [object FileList]
12-24 17:17:56.978: D/CordovaLog(4849): [0]
{"size":2422528,"lastModifiedDate":"2012-11-12T13:49:00.000Z","fileSize":24 22528,"name":"1352731741721.jpg","type":"image/jpeg","fileName":"1352731741 721.jpg"}

So things are being set correctly but I'd like to see the real path to the
file in there somewhere.

If you want I can send you a .jar/.js combo for you to test with your
upload script. Lemme know...

Simon Mac Donald
http://hi.im/simonmacdonald


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike Britton  
View profile  
 More options Dec 25 2012, 12:34 am
From: Mike Britton <mbritto...@gmail.com>
Date: Mon, 24 Dec 2012 21:34:34 -0800 (PST)
Local: Tues, Dec 25 2012 12:34 am
Subject: Re: [PhoneGap] Re: Input type = "file" button disabled in ICS / Phonegap 2.2

Using ICS, I'm seeing the file name only in the input tag.  Default browser.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Maulik Gordhandas  
View profile  
 More options Jan 14, 12:52 am
From: Maulik Gordhandas <mgordhan...@gmail.com>
Date: Sun, 13 Jan 2013 21:52:07 -0800 (PST)
Local: Mon, Jan 14 2013 12:52 am
Subject: Re: [PhoneGap] Re: Input type = "file" button disabled in ICS / Phonegap 2.2

Hi Mike,

I tried the above code using JellyBean [4.2] on Nexus 7 but the when i
press the choose file button nothing popups.

Please help.

Thanks


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Maulik Gordhandas  
View profile  
 More options Jan 14, 1:16 am
From: Maulik Gordhandas <mgordhan...@gmail.com>
Date: Sun, 13 Jan 2013 22:16:26 -0800 (PST)
Local: Mon, Jan 14 2013 1:16 am
Subject: Re: [PhoneGap] Re: Input type = "file" button disabled in ICS / Phonegap 2.2

Hi,

I tried to run the above code under jellybean 4.2 under my Nexus 7. it
doesnt work. tried the code under emulator seems to be working file.

Can you please verify the same?

Thanks


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Maulik Gordhandas  
View profile  
 More options Jan 14, 1:37 am
From: Maulik Gordhandas <mgordhan...@gmail.com>
Date: Sun, 13 Jan 2013 22:37:54 -0800 (PST)
Local: Mon, Jan 14 2013 1:37 am
Subject: Re: Input type = "file" button disabled in ICS / Phonegap 2.2

Alongside, is it possible to have an intent which allows files from other
apps as well and not just gallery..

thanks


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Simon MacDonald  
View profile  
 More options Jan 17, 11:00 pm
From: Simon MacDonald <simon.macdon...@gmail.com>
Date: Thu, 17 Jan 2013 23:00:01 -0500
Local: Thurs, Jan 17 2013 11:00 pm
Subject: Re: [PhoneGap] Re: Input type = "file" button disabled in ICS / Phonegap 2.2

I pushed my code to the Android repo today. Joe made some tweaks and basic
support will be in 2.4.0.

Simon Mac Donald
http://hi.im/simonmacdonald


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jake Johnson  
View profile  
 More options Feb 18, 12:04 pm
From: Jake Johnson <jakejohnso...@gmail.com>
Date: Mon, 18 Feb 2013 09:04:09 -0800 (PST)
Local: Mon, Feb 18 2013 12:04 pm
Subject: Re: [PhoneGap] Re: Input type = "file" button disabled in ICS / Phonegap 2.2

Mike, could you share your ChildBrowser update for cordova that allows you
to use html <input type='file' />  ?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
PatrickF  
View profile  
 More options Feb 27, 10:23 pm
From: PatrickF <patr...@premobile.net>
Date: Wed, 27 Feb 2013 19:23:56 -0800 (PST)
Local: Wed, Feb 27 2013 10:23 pm
Subject: Re: [PhoneGap] Re: Input type = "file" button disabled in ICS / Phonegap 2.2

On Anodroid 2.3.6, I can only see the file name in the input field, but
cannot retrieve it as value.

<input type="file" id="filname" />
$('#filname').change(function() {
console.log($(this).val());

}

Here's a screen shot<https://www.box.com/shared/static/2jy0a18bkvpgx6o1tb58.png>

Any help with this would be greatly appreciated.
Thanks
Patrick


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »