File-service
A scalable, universal file server that is based on ASP.
Typically, back-end projects may have upload/download requirements for avatar, picture, audio, video, and so on, which can be abstracted as file services.
Functional characteristics
- Support for Linux (recommended), Windows
- Scalable architecture to support the deployment of 1-n file servers
- An API interface for restful architectures that supports multiple language clients
- Supports file seconds, breakpoint continuation, remote pull upload
- Support for specifying disk space quotas for users
- Support for custom file processors
Project Address
Https://github.com/md-frank/file-service
System architecture
- File upload/download usually by the client directly with the file server interaction, upload needs to provide on behalf of the user identity token (generated by the Business Server), the successful return to the file root address.
- You can also upload the root address of the file directly to the client by the Business Server.
- The source contains the. Net Standard-based service-side SDK, which can generate tokens, upload files, etc.
- The source contains the. Net standard-based client SDK, which can upload/download files, etc.
Back-end use
Configure the Business Server
//Startup.cs代码片段public void ConfigureServices(IServiceCollection services){ //.... services.AddFileService(opts => { opts.Host = "fs.mondol.info"; //文件服务器域名 opts.AppSecret = "xxxxxx"; //加密密钥,需要与文件服务器相同 });}
Generating an access token
IFileServiceManager fileSvceMgr; //此实例可通过DI框架获得//根据业务规定其意义,例如:1-代表管理员,2-代表用户var ownerType = 2;var ownerId = 2; //如果ownerType=2,则为用户IDvar validTime = TimeSpan.FromDays(2); //token有效期var ownerToken = fileSvceMgr.GenerateOwnerTokenString(ownerType, ownerId, validTime);
Front-end use
File Upload
IFileServiceClient fileClient; //此实例可通过DI框架获得var ownerToken = "业务服务器返回的token";var periodMinute = 0; //有效期,0不过期var updResult = await fileClient.UploadAsync(ownerToken, "文件路径", periodMinute);var url = updResult.Data.Url; //得到文件根地址
URL Format description
The full URL format is this:https://domain.com/{fileToken}/{handler}/{modifier}
fileToken
: is the unique identifier for this upload file
handler
: File processor, can be image (picture processor), video (audio processor), Raw (return to original file), etc.
modifier
: "Optional" file processor parameter, for example, image processor, you can specify 128x128_png
After the successful upload of the file, it 文件根地址(updResult.Data.Url)
is up to the client to https://domain.com/{filetoken},url the back part.
The following examples illustrate:
Download the original file
File root address/raw, for example:
http://file.domain.com/files/1iYQTU7fEUgaa~URSVwaCqQKFml_IAAAAAgAAAAbhmsFjiUUQwCPn2ngI1QcvsSp0AA/raw
Download thumbnails of 128x128 size (original file is image)
File root address/image/128x128, for example:
http://file.domain.com/files/1iYQTU7fEUgaa~URSVwaCqQKFml_IAAAAAgAAAAbhmsFjiUUQwCPn2ngI1QcvsSp0AA/image/128x128
Download 128 wide, higher than scaled thumbnail (original file is image)
File root address/image/128x, for example:
http://file.domain.com/files/1iYQTU7fEUgaa~URSVwaCqQKFml_IAAAAAgAAAAbhmsFjiUUQwCPn2ngI1QcvsSp0AA/image/128x
The original image is in JPG format and the PNG format is downloaded.
File root address/image/raw_png, for example:
http://file.domain.com/files/1iYQTU7fEUgaa~URSVwaCqQKFml_IAAAAAgAAAAbhmsFjiUUQwCPn2ngI1QcvsSp0AA/image/raw_png
The original image is JPG format, download the PNG format 128x128 size thumbnail
File root address/image/128x128_png, for example:
http://file.domain.com/files/1iYQTU7fEUgaa~URSVwaCqQKFml_IAAAAAgAAAAbhmsFjiUUQwCPn2ngI1QcvsSp0AA/image/128x128_png
Open source file Server File-service Introduction