From 6e192e1765abb3d0a716c57af19596e904d77e98 Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Thu, 16 May 2024 13:14:16 +0500 Subject: [PATCH] s3: return 0 on failure instead of null when getting attachment size --- Notesnook.API/Interfaces/IS3Service.cs | 2 +- Notesnook.API/Services/S3Service.cs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Notesnook.API/Interfaces/IS3Service.cs b/Notesnook.API/Interfaces/IS3Service.cs index 4fbae1c..2384cfe 100644 --- a/Notesnook.API/Interfaces/IS3Service.cs +++ b/Notesnook.API/Interfaces/IS3Service.cs @@ -30,7 +30,7 @@ namespace Notesnook.API.Interfaces { Task DeleteObjectAsync(string userId, string name); Task DeleteDirectoryAsync(string userId); - Task GetObjectSizeAsync(string userId, string name); + Task GetObjectSizeAsync(string userId, string name); string GetUploadObjectUrl(string userId, string name); string GetDownloadObjectUrl(string userId, string name); Task StartMultipartUploadAsync(string userId, string name, int parts, string uploadId = null); diff --git a/Notesnook.API/Services/S3Service.cs b/Notesnook.API/Services/S3Service.cs index 021b3a6..1f4f08b 100644 --- a/Notesnook.API/Services/S3Service.cs +++ b/Notesnook.API/Services/S3Service.cs @@ -137,14 +137,14 @@ namespace Notesnook.API.Services throw new Exception("Could not delete directory."); } - public async Task GetObjectSizeAsync(string userId, string name) + public async Task GetObjectSizeAsync(string userId, string name) { var url = this.GetPresignedURL(userId, name, HttpVerb.HEAD, S3ClientMode.INTERNAL); - if (url == null) return null; + if (url == null) return 0; var request = new HttpRequestMessage(HttpMethod.Head, url); var response = await httpClient.SendAsync(request); - return response.Content.Headers.ContentLength; + return response.Content.Headers.ContentLength ?? 0; }