* FileTest.cs: chore: 增加图片缩略图接口

* AVFile.cs:
oneRain 2019-08-27 17:05:49 +08:00
parent 13b0789d2b
commit 65b54eb5d3
2 changed files with 15 additions and 1 deletions

View File

@ -27,5 +27,13 @@ namespace LeanCloudTests {
Assert.NotNull(file.ObjectId);
TestContext.Out.WriteLine($"file: {file.ObjectId}, {file.Url}");
}
[Test]
public async Task Thumbnail() {
AVFile file = await AVFile.GetFileWithObjectIdAsync("5d64ac55d5de2b006c1fe3d8");
Assert.NotNull(file);
TestContext.Out.WriteLine($"url: {file.Url}");
TestContext.Out.WriteLine($"thumbnail url: {file.GetThumbnailUrl(28, 28)}");
}
}
}

View File

@ -243,6 +243,12 @@ namespace LeanCloud {
}
}
public string GetThumbnailUrl(int width, int height,
int quality = 100, bool scaleToFit = true, string format = "png") {
int mode = scaleToFit ? 2 : 1;
return $"{Url}?imageView/{mode}/w/{width}/h/{height}/q/{quality}/format/{format}";
}
internal static AVFileController FileController {
get {
return AVPlugins.Instance.FileController;
@ -587,7 +593,7 @@ namespace LeanCloud {
/// <remarks>获取之后并没有实际执行下载只是加载了文件的元信息以及物理地址Url
/// </remarks>
public static Task<AVFile> GetFileWithObjectIdAsync(string objectId, CancellationToken cancellationToken) {
string currentSessionToken = AVUser.CurrentUser.SessionToken;
string currentSessionToken = AVUser.CurrentUser?.SessionToken;
return FileController.GetAsync(objectId, currentSessionToken, cancellationToken).OnSuccess(_ => {
var filestate = _.Result;
return new AVFile(filestate);