如何在上传文件时添加进度条

编程入门 行业动态 更新时间:2024-10-09 23:15:33
本文介绍了如何在上传文件时添加进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在将文件传输到网址,我可以成功完成但我不知道如何获取已上传文件的进度,我需要在某些数字上取得进展

i am transferring file to a url, i could do it successfully but i dont know how to get the progress of the file that is been uploaded, i need to get progress in some numbers

fileTransfer.upload(file_path, api_endpoint, options, data) .then((data) => { // success console.log("success", JSON.parse(data['response'])); this.upload_success(); }, (err) => { // error this.failed_upload(); console.log('File failed uploaded.', err); })

我发现onProgress(听众) c在ionic2文档中哎呀我不知道如何使用可能有人给我一些例子

i found onProgress(Listener) check in ionic2 documentation i dont know how to use could some one give me some examples

更新完成文档后 https: //github/apache/cordova-plugin-file-transfer#example-with-upload-headers-and-progress-events-android-and-ios-only

fileTransfer.onProgress = function(progressEvent) { if (progressEvent) { console.log("progress success =====") } else { console.log("progress error =====") } };

如果我运行我看不到任何这些控制台我在文件传输代码下面添加了这个新代码。可能有人帮助我

if i run i could not see any of those console i added this new code below the file transfer code. could some one help me

推荐答案

你可以通过使用像这样的onProgress函数来显示progressBar

You can show progressBar by using onProgress function like this

public fileTransfer: TransferObject = this.transfer.create(); public upload(path,folder) { url="www.axmag/download/pdfurl-guide.pdf"; var trustHosts = true; this.presentLoading("Loading"); //**Progress Bar** this.fileTransfer.onProgress((e)=> { let prg=(e.lengthComputable) ? Math.round(e.loaded / e.total * 100) : -1; console.log("progress:"+prg); }); this.fileTransfer.upload(file_path, api_endpoint, options, data).then((entry) => { //handle success console.log('upload complete: ' ); }, (error) => { this.loader.dismiss(); alert('uploading faild: '); console.log(error); //handle error }); }

现在你可以调用upload()函数来上传文件

Now you can call upload() function to upload a file

更多推荐

如何在上传文件时添加进度条

本文发布于:2023-11-26 09:23:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1633547.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:上传文件   进度条   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!