# OnedriveFileTransfer **Repository Path**: sponge_bob/OnedriveFileTransfer ## Basic Information - **Project Name**: OnedriveFileTransfer - **Description**: 利用onedrive作为中小型项目的静态大文件储存平台。可以隐藏具体onedrive文件url信息,记录下载情况。利用云服务器做中转,搭配CDN,大大节约储存成本,提高资源下载速度。 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 3 - **Forks**: 0 - **Created**: 2019-08-21 - **Last Updated**: 2024-01-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # OnedriveServer #### 介绍 利用onedrive作为中小型项目的静态大文件储存平台。可以隐藏具体onedrive文件url信息,记录下载情况,多onedrive可同时使用。利用云服务器做中转,搭配CDN,大大节约储存成本,提高资源下载速度。 #### 官方地址 [onedrive文档地址](https://docs.microsoft.com/en-us/onedrive/developer/rest-api/?view=odsp-graph-online) [注册app地址](https://apps.dev.microsoft.com/?referrer=https%3a%2f%2fdocs.microsoft.com%2fen-us%2fonedrive%2fdeveloper%2frest-api%2fgetting-started%2fgraph-oauth%3fview%3dodsp-graph-online#) 1、注册时填写的redirecturl一般是http://localhost 2、注册app时需要在API permissions添加offline_access和Files.ReadWrite.All权限。这两个权限在**Microsoft Graph**->Delegated permissions这里权限列表 3、在Certificates & secrets申请一个app secret,保存好这个app secret 4、在Overview查看application(client)Id,保存下来 #### 安装步骤 注:onedrive账号一定要可以使用三方APP,有管理员账号。 1、环境 java和mysql即可 2、阅读和修改src/main/resources/application.yml配置文件,添加mysql连接信息,修改init标签下的配置。注意,在init下的client_id一定要和tbl_api_config匹配的**id**匹配。 3、在mysql导入根目录下的sql文件,在tbl_api_config表中填入在Azure申请的client_id和client_secret。如果有多个onedrive账号就添加多个。在tbl_common_config配置默认扫描文件地址(后面查看文件时当做默认地址)。 4、启动项目。 5、初始化token,如果数据库中没有refresh_token,就是**URL说明**的第1和2步。如果有,就直接第二步 #### URL说明 成功code为0,失败code为10001开始 1、获取认证code的url get: getAuthCodeUrl/{id} {id}为tal_api_config表的id 2、将第1步的跳转的url后的code=xxxxxxxxxxx的xxxxxxxxxxx保存下来, get: code/{id}/{code} {id}为tal_api_config表的id,{code}为上面保存的xxxxxxxxxxx,这样就完成了初始化认证。在后面,如果{code}为**一个数字**的话就会**利用refresh_token刷新token**。 3、获取上传文件的session get: getUploadSession?remoteFileDir=aa&remoteFileName=bb&apiConfigId=cc aa为在onedrive上的文件夹路径。bb为下载文件时的名字,这里的bb并不是该文件在onedrive上的名字,onedrive上的名字是由uuid生成的,避免oendrive上同名文件给加上“(1)”这种。cc为apiconfig的id,为了确定该文件上传到哪个onedrive云盘。获取到uploadSession后将会保存到数据到tbl_onedrive_file_info和tbl_upload_info两张表,返回tbl_onedrive_file_info的fileId。 4、上传服务器文件到onedrive post: uploadFile?path=服务器文件绝对路径&uploadId=第3步获取的fileId 这里上传的为服务器的文件。返回一个uploadId 5、获取上传情况 get: getUploadStatus/{uploadId} {uploadId}为第3步获取的uplaodId,返回上传的total和offset 6、获取下载文件的流 dizhiget: /file/{fileId} 当我们上传完成后,可以利用第3步的fileId来获取下载流 7、获取在tbl_common_config或者请求参数path下的所有文件 get: getDirectoryAllFile?path=文件夹在服务器文件系统的绝对位置(可不传这个参数) 如股票不传path参数,则按照tbl_common_conifg中配置的 8、获取token的状态 getTokenStatus/{id} {id}为tal_api_config表的id,null 代表token没有获取