javascript 如何在phonegap中使用输入类型文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17439220/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 08:19:21  来源:igfitidea点击:

How to use input type file in phonegap?

javascriptandroidcordovasencha-touch

提问by SSS

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??

如何在 phonegap 中使用 html 文件属性?这样我就可以从我的 android 设备浏览任何 .txt 文件并将其上传到服务器?

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 :

我在 phonegap 文档中阅读了文件传输方法,但根据它可以仅通过 url 将文件上传到服务器。但是是否可以通过以下正常方式进行:

<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 .

input type="file" accept="image/*" 在手机间隙中不起作用?我查看了此链接,但仅适用于图像。

But how to upload the text files ?

但是如何上传文本文件?

Any help??

有什么帮助吗??

Can anybody answer this?

有人可以回答这个吗?

回答by Tombeau

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

您不能在 Phonegap 上使用输入文件。不支持。你需要做这样的事情:

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

在 mime type 中输入文件类型

回答by A. Magalh?es

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

我写了这个答案“你不能在 Phonegap 上使用输入文件。它不受支持。”。检查https://stackoverflow.com/a/13862151/1853864上的解决方案