我正在phonegap android中创建一个应用程序,我想在其中上传文件到服务器.我想要的是当用户点击上传按钮时,将打开一个选项对话框,用户将从该位置选择要上传的文件,然后当用户点击保存按钮时,将上传文件.对话框将像普通窗口一样,就像我们在桌面上点击邮件中的附加按钮时看到的那样.
任何人都可以告诉我如何在Android手机中这样做?
任何帮助表示赞赏.
提前致谢.
解决方法:
使用phonegap文件传输方法
FileTransfer对象允许您上传文件或从服务器下载文件.
属性
> onprogress:每当传输新的数据块时,使用ProgressEvent调用. (功能)
方法
> upload:将文件发送到服务器.
>下载:从服务器下载文件.
> abort:中止正在进行的转移.
样品
// !!假设变量fileURI包含设备上文本文件的有效URI
var win = function (r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
}
var fail = function (error) {
alert("An error has occurred: Code = " + error.code);
console.log("upload error source " + error.source);
console.log("upload error target " + error.target);
}
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = fileURI.substr(fileURI.lastIndexOf('/') + 1);
options.mimeType = "text/plain";
var params = {};
params.value1 = "test";
params.value2 = "param";
options.params = params;
var ft = new FileTransfer();
ft.upload(fileURI, encodeURI("http://some.server.com/upload.php"), win, fail, options);
您可以使用浏览和选择文件
var source = navigator.camera.PictureSourceType.PHOTOLIBRARY;
navigator.camera.getPicture(successFn, errorFn, { quality: 50,
destinationType: this.photoDestinationType.FILE_URI,
sourceType: source,
mediaType: navigator.camera.MediaType.ALLMEDIA });
更多信息检查link
原文地址:https://codeday.me/bug/20190624/1282639.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。