From 8b7f6597c8c0e38064134d16f2b83c4dedeb808b Mon Sep 17 00:00:00 2001 From: Claudia Murialdo Date: Mon, 6 Sep 2021 09:37:55 -0300 Subject: [PATCH 1/2] Fix Amazon.S3.AmazonS3Exception: Could not determine content length error when uploading from a stream to s3. --- .../Providers/Storage/GXAmazonS3/ExternalProviderS3.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dotnet/src/dotnetframework/Providers/Storage/GXAmazonS3/ExternalProviderS3.cs b/dotnet/src/dotnetframework/Providers/Storage/GXAmazonS3/ExternalProviderS3.cs index c7a26cd14..7a7aad213 100644 --- a/dotnet/src/dotnetframework/Providers/Storage/GXAmazonS3/ExternalProviderS3.cs +++ b/dotnet/src/dotnetframework/Providers/Storage/GXAmazonS3/ExternalProviderS3.cs @@ -357,11 +357,13 @@ private S3CannedACL GetCannedACL(GxFileType acl) public string Upload(string fileName, Stream stream, GxFileType destFileType) { + MemoryStream ms = new MemoryStream(); + stream.CopyTo(ms);//can determine PutObjectRequest.Headers.ContentLength. Avoid error Could not determine content length PutObjectRequest objectRequest = new PutObjectRequest() { BucketName = Bucket, Key = fileName, - InputStream = stream, + InputStream = ms, CannedACL = GetCannedACL(destFileType) }; if (TryGetContentType(fileName, out string mimeType)) { From b80a64a6f3c8d8c101ad898a870668af21a932e7 Mon Sep 17 00:00:00 2001 From: Claudia Murialdo Date: Mon, 6 Sep 2021 20:13:40 -0300 Subject: [PATCH 2/2] Store temporalFile.GetURI() instead of temporalFile.GetAbsoluteName(). GetURI() returns the right full path for external files. --- dotnet/src/dotnetframework/GxClasses/Helpers/GXRestUtils.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet/src/dotnetframework/GxClasses/Helpers/GXRestUtils.cs b/dotnet/src/dotnetframework/GxClasses/Helpers/GXRestUtils.cs index b8ffa60af..f2198a30d 100644 --- a/dotnet/src/dotnetframework/GxClasses/Helpers/GXRestUtils.cs +++ b/dotnet/src/dotnetframework/GxClasses/Helpers/GXRestUtils.cs @@ -31,7 +31,7 @@ internal static bool IsUploadURL(HttpContext httpContext) } internal static void CacheUploadFile(string fileGuid, string realFileName, string realFileExtension, GxFile temporalFile, IGxContext gxContext) { - CacheAPI.FilesCache.Set(fileGuid, JSONHelper.Serialize(new UploadCachedFile() { path = temporalFile.GetAbsoluteName(), fileExtension = realFileExtension, fileName = realFileName }), GxRestPrefix.UPLOAD_TIMEOUT); + CacheAPI.FilesCache.Set(fileGuid, JSONHelper.Serialize(new UploadCachedFile() { path = temporalFile.GetURI(), fileExtension = realFileExtension, fileName = realFileName }), GxRestPrefix.UPLOAD_TIMEOUT); GXFileWatcher.Instance.AddTemporaryFile(temporalFile, gxContext); } internal static string GetUploadFileGuid()