问题
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