0

I am developing an android app using phonegap.

we need to access images on mobile and upload that to server. Iam using a html input tag to upload image

<input uploadonchange id="fileData" type="file" accept="image/*" name="upload" />

onchange I am calling method and reading file details to check the file name and type in js

var fileinput = document.getElementById("fileData");
var file = fileinput.files[0]

but iam not getting file details like type. i can see that file size is updated with actual file size, but the name of the file is not same as actual file name. type property is empty.

I tried to implement this on a html page and load it from chrome browser. it works fine there. and prompt i got on chrome is a "Choose an action" lightbox with camera,camcorder,soundrecorder,documents

when uploading from my android app i got android "Open from".

permissions in android manifest are

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <permission android:name="com.transmit.transmit.permission.C2D_MESSAGE" android:protectionLevel="signature" />
    <uses-permission android:name="com.transmit.transmit.permission.C2D_MESSAGE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.MANAGE_DOCUMENTS" />
    <uses-permission android:name="android.permission.CAMERA" />

android studio log's at hte time of uploading image

12-20 19:45:21.599    2452-2452/com.phonegap.helloworld D/CordovaActivity﹕ Paused the application!
12-20 19:45:21.600    2452-2452/com.phonegap.helloworld D/CordovaWebView﹕ Handle the pause
12-20 19:45:22.055    2452-2452/com.phonegap.helloworld W/IInputConnectionWrapper﹕ showStatusIcon on inactive InputConnection
12-20 19:45:32.152    2452-2452/com.phonegap.helloworld D/CordovaActivity﹕ Incoming Result
12-20 19:45:32.152    2452-2452/com.phonegap.helloworld D/CordovaActivity﹕ Request code = 5173
12-20 19:45:32.152    2452-2452/com.phonegap.helloworld D/CordovaActivity﹕ did we get here?
12-20 19:45:32.152    2452-2452/com.phonegap.helloworld D/CordovaActivity﹕ result = content://media/external/images/media/10249
12-20 19:45:32.153    2452-2452/com.phonegap.helloworld D/CordovaActivity﹕ Resuming the App

name attribute we see in javascript is not same as actual filename. androidstudio log "content://media/external/images/media/10249" there no such file in mobile.

Vardhan
  • 69
  • 5
  • are you trying on android 4.4? – jcesarmobile Dec 20 '14 at 09:39
  • try using this one, http://blog.revivalx.com/2014/07/12/upload-image-using-file-transfer-cordova-plugin-for-ios-and-android/ – Nurdin Dec 20 '14 at 11:51
  • @jcesarmobile yep my android version is 4.4.4 – Vardhan Dec 21 '14 at 10:08
  • The file chooser was broken on android 4.4, and they partially fixed it on android 4.4.3, but as you can see, some sources return an strange file path as you can see. Use the filechooser plugin to select the file instead, you can see a sample project on my answer here http://stackoverflow.com/questions/19882331/html-file-input-in-android-webview-android-4-4-kitkat – jcesarmobile Dec 21 '14 at 14:51

0 Answers0