{"id":19647213,"url":"https://github.com/lovefc/fcup2","last_synced_at":"2025-07-29T09:35:39.541Z","repository":{"id":57233780,"uuid":"238373279","full_name":"lovefc/fcup2","owner":"lovefc","description":"一个轻巧的js类库,用于在网页端上传大文件,大图片,可以设置多个上传参数,提供了多种回调. 可以任意绑定id,自动生成上传表单,可以自定义文件头,其它参数,设置最大上传,最小上传,以及判断上传类型.","archived":false,"fork":false,"pushed_at":"2022-06-05T14:24:26.000Z","size":470,"stargazers_count":21,"open_issues_count":0,"forks_count":8,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-22T17:13:02.374Z","etag":null,"topics":["html5up","upload","uploading-large-files","web-upload"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lovefc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-05T05:12:56.000Z","updated_at":"2024-04-25T02:51:55.000Z","dependencies_parsed_at":"2022-09-04T23:00:20.258Z","dependency_job_id":null,"html_url":"https://github.com/lovefc/fcup2","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovefc%2Ffcup2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovefc%2Ffcup2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovefc%2Ffcup2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovefc%2Ffcup2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lovefc","download_url":"https://codeload.github.com/lovefc/fcup2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251338634,"owners_count":21573588,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["html5up","upload","uploading-large-files","web-upload"],"created_at":"2024-11-11T14:42:54.139Z","updated_at":"2025-04-28T15:31:23.762Z","avatar_url":"https://github.com/lovefc.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"### 项目介绍\n\n一个轻巧的js类库,用于在网页端上传大文件,大图片,可以设置多个上传参数,提供了多种回调.\n可以任意绑定id,自动生成上传表单,可以自定义文件头,其它参数,设置最大上传,最小上传,以及判断上传类型.\n现在已经支持断点续传,并且有详细的操作案例\n\n官网：http://fcup.lovefc.cn\n\nGitee：https://gitee.com/lovefc/fcup2\n\nGithub：https://github.com/lovefc/fcup2\n\nNODE打包使用案例: https://gitee.com/lovefc/webpack\n\n![](/show.png)\n\n### 使用教程\n\n直接下载源码或者使用git克隆\n\n备注:新版本的demo使用了sqlite数据库,注意php环境有没有sqlite扩展,另外上传目录要给读写权限\n\n\n### 使用方法\n\n```javascript\n   // 上传案例2\n   let up = new fcup({\n\n      id: \"upid\", // 绑定id\n\n      url: \"server/php_db/upload.php\", // url地址\n\t  \n\t  check_url: \"server/php_db/check.php\", // 检查上传url地址\n\n      type: \"jpg,png,jpeg,gif\", // 限制上传类型，为空不限制\n\n      shard_size: \"0.005\", // 每次分片大小，单位为M，默认1M\n\n      min_size: '', // 最小文件上传M数，单位为M，默认为无\n\n      max_size: \"2\", // 上传文件最大M数，单位为M，默认200M\n      \n\t  // headers: {\"version\": \"fcup-v2.0\"}, // 附加的文件头,默认为null, 请注意指定header头时将不能进行跨域操作\n\t  \n\t  // apped_data: {}, //每次上传的附加数据\n\t  \n      // 定义错误信息\n      error_msg: {\n         1000: \"未找到上传id\",\n         1001: \"类型不允许上传\",\n         1002: \"上传文件过小\",\n         1003: \"上传文件过大\",\n         1004: \"上传请求超时\"\n      },\n      \n      // 错误提示\n      error: (msg) =\u003e {\n         alert(msg);\n      },      \n\n      // 初始化事件                \n      start: () =\u003e {\n         console.log('上传已准备就绪');\n         Progress2(0);\n      },\n\n      // 等待上传事件，可以用来loading\n      before_send: () =\u003e {\n         console.log('等待请求中');\n      },\n\n      // 上传进度事件\n      progress: (num, other) =\u003e {\n         Progress2(num);\n         console.log(num);\n         console.log('上传进度' + num);\n         console.log(\"上传类型\" + other.type);\n         console.log(\"已经上传\" + other.current);\n         console.log(\"剩余上传\" + other.surplus);\n         console.log(\"已用时间\" + other.usetime);\n         console.log(\"预计时间\" + other.totaltime);\n      },\n\t  \n      // 检查地址回调,用于判断文件是否存在,类型,当前上传的片数等操作\n      check_success: (res) =\u003e {\n\t  \n         let data = res ? eval('(' + res + ')') : '';\n\t\t \n\t\t let status = data.status;\n\t\t \n         let url = data.url;\n\t\t \n\t\t let msg = data.message;\n\t\t \n\t\t // 错误提示\n         if (status == 1 ) {\n            alert(msg);\n            return false;\n         }\n\t\t \n\t\t // 已经上传\n         if (status == 2) {\n\t\t\talert('文件已存在');\n            return false;\n         }\n         \n\t\t// 如果提供了这个参数,那么将进行断点上传的准备\n\t\tif(data.file_index){\n           // 起始上传的切片要从1开始\n\t\t   let file_index = data.file_index ? parseInt(data.file_index) : 1;\n           // 设置上传切片的起始位置\t\t   \n\t\t   up.set_shard(file_index);\n\t\t}\n\t\t \n        // 如果接口没有错误，必须要返回true，才不会终止上传\n         return true;\n      },\n\t  \n      // 上传成功回调，回调会根据切片循环，要终止上传循环，必须要return false，成功的情况下要始终返回true;\n      success: (res) =\u003e {\n\n         let data = res ? eval('(' + res + ')') : '';\n\n         let url = data.url + \"?\" + Math.random();\n\t\t \n\t\t let file_index = data.file_index ? parseInt(data.file_index) : 1;\n\n         if (data.status == 2) {\n            alert('上传完成');\n         }\n\n         // 如果接口没有错误，必须要返回true，才不会终止上传循环\n         return true;\n      }\n   });\t\t\n```\n\n### 前端参数详细\n\n| 参数 |类型| 空 | 默认 | 备注 |\n|----    |-------    |--- |---|------      | \n|id | string | 否 | 无 |     dom的id        | \n|url |string | 否 | 无  |   上传到服务器的url  |\n|check_url |string | 否 | 无  |   检查上传url地址  |\n|type |string | 是  |  空 |  限制上传类型，多个用,号分割(不区分大小写),为空不限制  |\n|shard_size    | int,float | 否   | 2   |     每次分片的大小,单位为M,因为要计算md5,所以如果条件允许,不要设定的太小     |\n|min_size    | int,float | 是   | 空   |  上传文件的最小M数   |\n|max_size    | int,float | 是   | 空   |  上传文件的最大M数   |\n|headers |object   |是   | 空  |  每次上传附带的文件头,请注意指定header头时将不能进行跨域操作 |\n|apped_data |object   |是   | 空  |  每次上传附带的其它参数,传递到后台  |\n|timeout |int   |否   | 3000 |  ajax超时时间  |\n|error_msg |object   |否   | object |  错误提示 | \n|start |function   |是   | fucntion |  实例化类后的开始事件  |\n|before_send |function   |是   | fucntion |  等待上传事件  |\n|progress |function   |是   | fucntion |  上传进度事件  |\n|error |function   |是   | fucntion |  内部的错误提示函数  |\n|check_success |function   |是   | fucntion |  检查地址回调,用于判断文件是否存在,类型,改变当前上传的片数等操作 |\n|success |function   |是   | fucntion |  数据成功传递到后端的事件,这是一个循环事件 |\n\n### 常用函数\n| 函数名 | 说明 |\n|----    |------      | \n|fcup.set_shard(file_index)|    设置当前的分片数起始数,用于断点上传时改变       | \n|fcup.cancel()|取消上传事件  |\n|fcup.start_upload()|开始上传事件  |\n\n### 后端参数详情\n\n|参数名|注释|\n|----    |------  |\n|file_data |分段的文件|\n|file_name |文件名称|\n|file_total |文件的总片数|\n|file_index |当前片数|\n|file_md5 |文件的md5|\n|file_size |文件的总大小|\n|file_chunksize |当前切片的文件大小|\n|file_suffix |文件的后缀名|\n- 备注：以post的方式传递到后端\n\n### 更新日志\n\n2018/1/8 : 添加了对于接口返回结果的回调，添加了对于上传表单id的指定\n\n2018/1/10 : 添加了node.js的上传接口，基于express框架(已丢弃)\n\n2018/1/17 : 优化了分片异步处理,队列执行接口,修复细节\n\n2018/5/02 : 添加了文件大小的判断,添加了对于文件md5的计算,添加了终止函数,传值到后台使用,优化细节部分\n\n2019/5/21 : 分离了原来的进度动画，现在用户可以自定义自己的动画和按钮，分别提供了各种回调事件以便处理\n\n2019/8/12 : 修复了获取md5值的bug，感谢Matty的提醒\n\n2019/10/22: 修改了终止事件循环执行的bug\n\n2020/01/05: 重新封装类库,优化性能,改掉了以前的bug \n\n2020/01/30: 优化了时间计算,添加了可自定义header头的功能\n\n2020/02/01: 多实例化,可以在同一个页面添加多个上传功能\n\n2020/04/16: 分离了文件判断和上传的操作,添加了断点续传功能\n\n2020/11/29: 修复了跨域上传的bug,请注意指定header头时将不能进行跨域操作\n\n2021/03/18: 添加了node上传案例,后端使用了fc-body插件来进行上传\n\n2021/08/20: 修改上传大小值限定精度问题\n\n2021/12/20: 规范了参数命名问题\n\n2022/06/05: 修复等待事件,感谢liming的发现和帮助","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flovefc%2Ffcup2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flovefc%2Ffcup2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flovefc%2Ffcup2/lists"}