How to use input type file in phonegap? [duplicate]

血红的双手。 提交于 2019-11-30 08:15:06

问题


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?


回答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




回答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



来源:https://stackoverflow.com/questions/17439220/how-to-use-input-type-file-in-phonegap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!