10

How to use html file attribute in phonegap ? so that i can browse any .txt file from my android device and upload it to the server??

I read file transfer method in phonegap documentation but according to that it is possible to upload files to the server only through url.But is it possible in normal way like :

<input type=file /><button>upload</button>

input type="file" accept="image/*" doesn't work in phone gap? i looked at this link but that says only for images .

But how to upload the text files ?

Any help??

Can anybody answer this?

Community
  • 1
  • 1
SSS
  • 1,380
  • 3
  • 28
  • 48

2 Answers2

-1

You can't use input file on Phonegap. It's not supported. You need make something like this:

function uploadDatabase(callback) {
// file.entry accessible from global scope; see other tutorial
var filepath = file.entry.fullPath,
    uploadOptions = new FileUploadOptions(),
    transfer = new FileTransfer(),
    endpoint = "http://facepath.com/payload";

uploadOptions.fileKey = "db";
uploadOptions.fileName = "database.db";
uploadOptions.mimeType = "text/plain";

transfer.upload(filepath, endpoint, transferComplete,
                        transferError, uploadOptions);

}

in mime type put the type of file

Tombeau
  • 353
  • 4
  • 14
-2

I wrote this answer "You can't use input file on Phonegap. It's not supported.". Check the solution on https://stackoverflow.com/a/13862151/1853864

Community
  • 1
  • 1
A. Magalhães
  • 1,511
  • 2
  • 22
  • 31
  • sorry. I am not looking for only images . I wanna upload files stored in sdcard to server . I mean i want browse option to browse any txt file from the sdcard and upload to the server. Is that possible in phonegap?? Or any other method? – SSS Jul 04 '13 at 03:32
  • You already try https://github.com/phonegap/phonegap-plugins/tree/master/Android/FileUploader? – A. Magalhães Jul 04 '13 at 09:47
  • 1
    Don't just add the same answer to a question requiring the same answer. Instead, mark the question as duplicate (if it's the case). – Bárbara Peres Oct 06 '19 at 07:34