{"id":16383311,"url":"https://github.com/hwholiday/file_storage","last_synced_at":"2025-03-23T03:33:26.964Z","repository":{"id":234684682,"uuid":"279226551","full_name":"hwholiday/file_storage","owner":"hwholiday","description":"文件服务器可分片，断点续传等","archived":false,"fork":false,"pushed_at":"2020-08-17T01:05:45.000Z","size":7404,"stargazers_count":20,"open_issues_count":0,"forks_count":8,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T17:24:49.345Z","etag":null,"topics":["file-slice","file-upload","filesystem"],"latest_commit_sha":null,"homepage":"","language":"Go","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/hwholiday.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,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2020-07-13T06:10:56.000Z","updated_at":"2024-10-21T06:42:49.000Z","dependencies_parsed_at":"2024-04-21T17:49:07.361Z","dependency_job_id":null,"html_url":"https://github.com/hwholiday/file_storage","commit_stats":null,"previous_names":["hwholiday/file_storage"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hwholiday%2Ffile_storage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hwholiday%2Ffile_storage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hwholiday%2Ffile_storage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hwholiday%2Ffile_storage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hwholiday","download_url":"https://codeload.github.com/hwholiday/file_storage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245052646,"owners_count":20553162,"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":["file-slice","file-upload","filesystem"],"created_at":"2024-10-11T04:07:57.658Z","updated_at":"2025-03-23T03:33:26.472Z","avatar_url":"https://github.com/hwholiday.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# file_storage\n参照 Telegram [Uploading and Downloading Files](https://core.telegram.org/api/files)  \n 写的文件服务器（断点续传，分片上传下载,自动生成缩略图等）\n\n申请上传文件\n---\n请求\n   - 文件名\n   - 文件大小 （字节）\n   - 文件扩展名 \n   - 是否需要缩略图\n   - 文件MD5\n\n返回\n   - 文件id\n   - 上传过期时间，到时间未上传完，自动清理\n\n\n取消上传文件\n---\n请求\n   - 文件ID\n    \n返回\n   - 成功 or 失败\n   \n\n获取文件信息\n---\n请求\n   - 文件ID\n    \n返回\n   - 文件信息\n   \n上传文件\n---\n请求\n\n   - 文件ID\n   - 文件分片ID file_part\n   - 文件MD5\n   - 文件内容 part_size\n   - 是否是最后一片\n###### 所有分片必须具有相同的大小（part_size），并且必须满足以下条件：part_size % 1024 = 0 （可被1KB整除524288 % part_size = 0（512KB必须可以被part_size整除）如果最后一部分的大小小于part_size，则不必满足这些条件。每个部分都应具有序列号file_part，其值的范围为1到3000。\n\n服务器处理 \n        \n- 每个分片接收完毕的时候都检查下服务器接受文件MD5是否相等\n- 检查该分片是否已经上传，是则不做任何处理,不是则把文件存入内存，再将已上传文件大小累加\n- 判断已上传文件大小是否等于文件总大小 （标记文件已经完成）\n- 按照文件分片顺序拼接文件\n- 检查文件MD5是否相等，上传到文件服务器,文件上传结束\n\n返回\n   - 成功 or 失败\n\n\n下载文件\n---\n请求\n   - 文件ID\n   - limit  可被1024整除\n   - offset 可被1024整除\n   - offset 不能超过 1048576（1 MB）\n\n服务器处理\n- minio GetObject 可配置 \n```\nvar opt minio.GetObjectOptions\nerr := opt.SetRange(start, end)\nGetObject(bucketName, fileName, opt)\n```\n\n\n返回\n   - 文件信息     \n \n\n\n## 对外方法 \n```bash\n//申请上传文件ID\nApplyFid(info *storage.InApplyFid) (out *storage.OutApplyFid, err error) \n//通过文件MD5获取服务器文件信息\nGetPbFileInfoByMd5(md5 string) (fileInfo *storage.FileInfo, err error)\n//通过文件ID获取服务器文件信息\nGetPbFileInfoByFid(fid int64) (fileInfo *storage.FileInfo, err error)\n//上传分片文件\nUpSliceFile(in *storage.InUpSliceFileItem) (err error)\n//分片下载文件\nDownSliceFile(in *storage.InDownSliceFileItem) (out *storage.OutDownSliceFileItem, err error)\n//上传不分片文件\nUpFile(in *storage.InUpFile) (err error)\n//下载不分片文件\nGetFile(fid int64) (out *storage.OutDownFile, err error)\n//取消上传\nCancelByFid(info *storage.InCancelUpload) (err error)\n```   \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhwholiday%2Ffile_storage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhwholiday%2Ffile_storage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhwholiday%2Ffile_storage/lists"}