From 65b54eb5d3dc44dbcfed1a422b61212bbff6cd39 Mon Sep 17 00:00:00 2001 From: oneRain Date: Tue, 27 Aug 2019 17:05:49 +0800 Subject: [PATCH] =?UTF-8?q?*=20FileTest.cs:=20chore:=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E7=BC=A9=E7=95=A5=E5=9B=BE=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * AVFile.cs: --- Storage/Storage.Test/FileTest.cs | 8 ++++++++ Storage/Storage/Public/AVFile.cs | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Storage/Storage.Test/FileTest.cs b/Storage/Storage.Test/FileTest.cs index 2e5c287..e82d57b 100644 --- a/Storage/Storage.Test/FileTest.cs +++ b/Storage/Storage.Test/FileTest.cs @@ -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)}"); + } } } diff --git a/Storage/Storage/Public/AVFile.cs b/Storage/Storage/Public/AVFile.cs index d2f4cbe..3d05878 100644 --- a/Storage/Storage/Public/AVFile.cs +++ b/Storage/Storage/Public/AVFile.cs @@ -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 { /// 获取之后并没有实际执行下载,只是加载了文件的元信息以及物理地址(Url) /// public static Task 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);