diff --git a/oss/source/custom-code/IOSSFileTransfer.cs b/oss/source/custom-code/IOSSFileTransfer.cs index 4406218..5d8338c 100644 --- a/oss/source/custom-code/IOSSFileTransfer.cs +++ b/oss/source/custom-code/IOSSFileTransfer.cs @@ -36,7 +36,12 @@ Task Upload( string accessToken, CancellationToken cancellationToken, string requestIdPrefix = "", - IProgress progress = null); + IProgress progress = null, + string xAdsMetaContentType = default(string), + string xAdsMetaContentDisposition = default(string), + string xAdsMetaContentEncoding = default(string), + string xAdsMetaCacheControl = default(string), + string xAdsUserDefinedMetadata = default(string)); Task Download( string bucketKey, diff --git a/oss/source/custom-code/OSSFileTransfer.cs b/oss/source/custom-code/OSSFileTransfer.cs index 8b44dbc..130ddcf 100644 --- a/oss/source/custom-code/OSSFileTransfer.cs +++ b/oss/source/custom-code/OSSFileTransfer.cs @@ -114,7 +114,12 @@ public async Task Upload( string accessToken, CancellationToken cancellationToken, string requestIdPrefix = "", - IProgress progress = null) + IProgress progress = null, + string xAdsMetaContentType = default(string), + string xAdsMetaContentDisposition = default(string), + string xAdsMetaContentEncoding = default(string), + string xAdsMetaCacheControl = default(string), + string xAdsUserDefinedMetadata = default(string)) { var requestId = HandleRequestId(requestIdPrefix, bucketKey, objectKey); var retryCount = _configuration.GetRetryCount(); @@ -226,7 +231,12 @@ public async Task Upload( { UploadKey = uploadKey }, - accessToken: accessToken); + accessToken: accessToken, + xAdsMetaContentType: xAdsMetaContentType, + xAdsMetaContentDisposition: xAdsMetaContentDisposition, + xAdsMetaContentEncoding: xAdsMetaContentEncoding, + xAdsMetaCacheControl: xAdsMetaCacheControl, + xAdsUserDefinedMetadata: xAdsUserDefinedMetadata); progress?.Report(100); return completeResponse; diff --git a/oss/source/custom-code/OssClient.cs b/oss/source/custom-code/OssClient.cs index 7e12e9f..1c2b9e9 100644 --- a/oss/source/custom-code/OssClient.cs +++ b/oss/source/custom-code/OssClient.cs @@ -80,8 +80,23 @@ public OssClient(SDKManager.SDKManager sdkManager = default, IAuthenticationProv /// An access token obtained by a call to GetThreeLeggedTokenAsync() or GetTwoLeggedTokenAsync(). /// (optional) /// + /// + ///The Content-Type value for the uploaded object to record within OSS. (optional) + /// + /// + ///The Content-Disposition value for the uploaded object to record within OSS. (optional) + /// + /// + ///The Content-Encoding value for the uploaded object to record within OSS. (optional) + /// + /// + ///The Cache-Control value for the uploaded object to record within OSS. (optional) + /// + /// + ///Custom metadata to be stored with the object, which can be retrieved later on download or when retrieving object details. Must be a JSON object that is less than 100 bytes. (optional) + /// /// Task of <Upload> - public async System.Threading.Tasks.Task UploadObjectAsync(string bucketKey, string objectKey, Stream sourceToUpload, CancellationToken cancellationToken = default, string requestIdPrefix = "", IProgress progress = null, string accessToken = default) + public async System.Threading.Tasks.Task UploadObjectAsync(string bucketKey, string objectKey, Stream sourceToUpload, CancellationToken cancellationToken = default, string requestIdPrefix = "", IProgress progress = null, string accessToken = default, string xAdsMetaContentType = default(string), string xAdsMetaContentDisposition = default(string), string xAdsMetaContentEncoding = default(string), string xAdsMetaCacheControl = default(string), string xAdsUserDefinedMetadata = default(string)) { if (String.IsNullOrEmpty(accessToken) && this.AuthenticationProvider == null) { @@ -91,7 +106,7 @@ public async System.Threading.Tasks.Task UploadObjectAsync(string { accessToken = await this.AuthenticationProvider.GetAccessToken(); } - var response = await this.oSSFileTransfer.Upload(bucketKey, objectKey, sourceToUpload, accessToken, cancellationToken, requestIdPrefix, progress); + var response = await this.oSSFileTransfer.Upload(bucketKey, objectKey, sourceToUpload, accessToken, cancellationToken, requestIdPrefix, progress, xAdsMetaContentType,xAdsMetaContentDisposition, xAdsMetaContentEncoding, xAdsMetaCacheControl, xAdsUserDefinedMetadata); var apiResponse = new ApiResponse(response, await LocalMarshalling.DeserializeAsync(response.Content)); return apiResponse.Content; } @@ -128,9 +143,24 @@ public async System.Threading.Tasks.Task UploadObjectAsync(string /// An access token obtained by a call to GetThreeLeggedTokenAsync() or GetTwoLeggedTokenAsync(). /// (optional) /// + /// + ///The Content-Type value for the uploaded object to record within OSS. (optional) + /// + /// + ///The Content-Disposition value for the uploaded object to record within OSS. (optional) + /// + /// + ///The Content-Encoding value for the uploaded object to record within OSS. (optional) + /// + /// + ///The Cache-Control value for the uploaded object to record within OSS. (optional) + /// + /// + ///Custom metadata to be stored with the object, which can be retrieved later on download or when retrieving object details. Must be a JSON object that is less than 100 bytes. (optional) + /// /// Task of <Upload> - public async System.Threading.Tasks.Task UploadObjectAsync(string bucketKey, string objectKey, string sourceToUpload, CancellationToken cancellationToken = default, string requestIdPrefix = "", IProgress progress = null, string accessToken = default) - { + public async System.Threading.Tasks.Task UploadObjectAsync(string bucketKey, string objectKey, string sourceToUpload, CancellationToken cancellationToken = default, string requestIdPrefix = "", IProgress progress = null, string accessToken = default, string xAdsMetaContentType = default(string), string xAdsMetaContentDisposition = default(string), string xAdsMetaContentEncoding = default(string), string xAdsMetaCacheControl = default(string), string xAdsUserDefinedMetadata = default(string)) + { if (String.IsNullOrEmpty(accessToken) && this.AuthenticationProvider == null) { throw new Exception("Please provide a valid access token or an authentication provider"); @@ -141,7 +171,7 @@ public async System.Threading.Tasks.Task UploadObjectAsync(string } FileStream fileStream = File.OpenRead(sourceToUpload); - var response = await this.oSSFileTransfer.Upload(bucketKey, objectKey, fileStream, accessToken, cancellationToken, requestIdPrefix, progress); + var response = await this.oSSFileTransfer.Upload(bucketKey, objectKey, fileStream, accessToken, cancellationToken, requestIdPrefix, progress, xAdsMetaContentType, xAdsMetaContentDisposition, xAdsMetaContentEncoding, xAdsMetaCacheControl, xAdsUserDefinedMetadata); var apiResponse = new ApiResponse(response, await LocalMarshalling.DeserializeAsync(response.Content)); return apiResponse.Content; } diff --git a/oss/test/TestOss.cs b/oss/test/TestOss.cs index ae7a001..105f9f8 100644 --- a/oss/test/TestOss.cs +++ b/oss/test/TestOss.cs @@ -18,8 +18,13 @@ public class TestOss string? filePath = Environment.GetEnvironmentVariable("FILE_PATH"); // Signed Url Format: "https://developer.api.autodesk.com/oss/v2/signedresources/?region=US" string? signedUrl = Environment.GetEnvironmentVariable("SIGNED_URL"); + string? xAdsMetaContentType = Environment.GetEnvironmentVariable("XADS_META_CONTENT_TYPE"); + string? xAdsMetaContentDisposition = Environment.GetEnvironmentVariable("XADS_META_CONTENT_DISPOSITION"); + string? xAdsMetaContentEncoding = Environment.GetEnvironmentVariable("XADS_META_CONTENT_ENCODING"); + string? xAdsMetaCacheControl = Environment.GetEnvironmentVariable("XADS_META_CACHE_CONTROL"); + string? xAdsUserDefinedMetadata = Environment.GetEnvironmentVariable("XADS_USER_DEFINED_METADATA"); - [ClassInitialize] +[ClassInitialize] public static void ClassInitialize(TestContext testContext) { var sdkManager = SdkManagerBuilder @@ -84,7 +89,30 @@ public async Task TestUploadObjectAsync() bucketKey: bucketKey, objectKey: objectKey, sourceToUpload: sourceToUpload, - cancellationToken: CancellationToken.None); + cancellationToken: CancellationToken.None, + xAdsMetaContentType: xAdsMetaContentType, + xAdsMetaContentDisposition: xAdsMetaContentDisposition, + xAdsMetaContentEncoding: xAdsMetaContentEncoding, + xAdsMetaCacheControl: xAdsMetaCacheControl, + xAdsUserDefinedMetadata: xAdsUserDefinedMetadata); + Assert.IsTrue(objectDetails.ObjectId.Equals($"urn:adsk.objects:os.object:{bucketKey}/{objectKey}")); + } + + [TestMethod] + public async Task TestUploadObjectStreamAsync() + { + using var fileStream = File.OpenRead(sourceToUpload); + ObjectDetails objectDetails = await _ossClient.UploadObjectAsync( + accessToken: token, + bucketKey: bucketKey, + objectKey: objectKey, + sourceToUpload: fileStream, + cancellationToken: CancellationToken.None, + xAdsMetaContentType: xAdsMetaContentType, + xAdsMetaContentDisposition: xAdsMetaContentDisposition, + xAdsMetaContentEncoding: xAdsMetaContentEncoding, + xAdsMetaCacheControl: xAdsMetaCacheControl, + xAdsUserDefinedMetadata: xAdsUserDefinedMetadata); Assert.IsTrue(objectDetails.ObjectId.Equals($"urn:adsk.objects:os.object:{bucketKey}/{objectKey}")); }