Skip to content

Commit

Permalink
Merge pull request #48 from autodesk-platform-services/DAS-215
Browse files Browse the repository at this point in the history
Upload function now accept memory stream and consumed docs team changes
  • Loading branch information
sajith-subramanian authored Jun 28, 2024
2 parents 9fb01ad + c2e515b commit 19319c3
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 48 deletions.
4 changes: 2 additions & 2 deletions oss/source/Http/BucketsApi.gen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public interface IBucketsApi
///
///Buckets are virtual container within the Object Storage Service (OSS), which you can use to store and manage objects (files) in the cloud. The application creating the bucket is the owner of the bucket.
///
///**Note:** Do not use this operation to create buckets for BIM360 Document Management. Use [POST projects/{project_id}/storage](/en/docs/data/v2/reference/http/projects-project_id-storage-POST>_ instead. For details, see `Upload Files to BIM 360 Document Management </en/docs/bim360/v1/tutorials/document-management/upload-document).
///**Note:** Do not use this operation to create buckets for BIM360 Document Management. Use [POST projects/{project_id}/storage](/en/docs/data/v2/reference/http/projects-project_id-storage-POST>) instead. For details, see [Upload Files to BIM 360 Document Management](/en/docs/bim360/v1/tutorials/document-management/upload-document).
/// </remarks>
/// <exception cref="HttpRequestException">Thrown when fails to make API call</exception>
/// <param name="policyKey">
Expand All @@ -62,7 +62,7 @@ public interface IBucketsApi
/// </param>
/// <returns>Task of ApiResponse&lt;Bucket&gt;</returns>

System.Threading.Tasks.Task<ApiResponse<Bucket>> CreateBucketAsync(CreateBucketsPayload policyKey, Region xAdsRegion , string accessToken = null, bool throwOnError = true);
System.Threading.Tasks.Task<ApiResponse<Bucket>> CreateBucketAsync(CreateBucketsPayload policyKey, Region xAdsRegion, string accessToken = null, bool throwOnError = true);
/// <summary>
/// Delete Bucket
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions oss/source/Model/Access.gen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
namespace Autodesk.Oss.Model
{
/// <summary>
/// Access for signed resource Acceptable values: read, write, readwrite Default value: read
/// Access for signed resource Possible values: read, write, readwrite Default value: read
/// </summary>
///<value>Access for signed resource Acceptable values: read, write, readwrite Default value: read</value>
///<value>Access for signed resource Possible values: read, write, readwrite Default value: read</value>

[JsonConverter(typeof(StringEnumConverter))]

Expand Down
5 changes: 4 additions & 1 deletion oss/source/Model/Batchsigneds3downloadResponse.gen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ public Batchsigneds3downloadResponse()
}

/// <summary>
///Gets or Sets Results
///A map of the returned results; each key in the map corresponds to an object key in the batch, and the value includes the results for that object.
/// </summary>
/// <value>
///A map of the returned results; each key in the map corresponds to an object key in the batch, and the value includes the results for that object.
/// </value>
[DataMember(Name="results", EmitDefaultValue=false)]
public Dictionary<string, DownloadResults> Results { get; set; }

Expand Down
5 changes: 4 additions & 1 deletion oss/source/Model/Batchsigneds3uploadResponse.gen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ public Batchsigneds3uploadResponse()
}

/// <summary>
///Gets or Sets Results
///A map of the returned results; each key in the map corresponds to an object key in the batch, and the value includes the results for that object.
/// </summary>
/// <value>
///A map of the returned results; each key in the map corresponds to an object key in the batch, and the value includes the results for that object.
/// </value>
[DataMember(Name="results", EmitDefaultValue=false)]
public Dictionary<string, Batchsigneds3uploadResponseResultsValue> Results { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion oss/source/Model/DownloadResults.gen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
namespace Autodesk.Oss.Model
{
/// <summary>
/// An object that represents the response to a Batch Generate Signed S3 Download URLs operation. **Note**: objectKeyN is a placeholder for the first object key for which the client requested a download signed URL. The attributes within contain the success data / error information for the request for that object. &#x60;results&#x60; will contain one such attribute for each requested object in the batch.
/// An object that represents the response to a Batch Generate Signed S3 Download URLs operation. **Note**: &#x60;&#x60;objectKeyN&#x60;&#x60; is a placeholder for the first object key for which the client requested a download signed URL. The attributes within contain the success data / error information for the request for that object. &#x60;results&#x60; will contain one such attribute for each requested object in the batch.
/// </summary>
[DataContract]
public partial class DownloadResults
Expand Down
4 changes: 2 additions & 2 deletions oss/source/Model/Region.gen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
namespace Autodesk.Oss.Model
{
/// <summary>
/// Specifies where the bucket containing the object stored. Possible values are:
/// Specifies where the bucket containing the object is stored. Possible values are:
///
/// - `US` - (Default) Data center for the US region.
/// - `EMEA` - Data center for the European Union, Middle East, and Africa.
/// - `APAC` - (Beta) Data center for Australia.
///
/// **Note:** Beta features are subject to change. Please do not use in production environments.
/// </summary>
///<value>Specifies where the bucket containing the object stored. Possible values are:
///<value>Specifies where the bucket containing the object is stored. Possible values are:
///
/// - `US` - (Default) Data center for the US region.
/// - `EMEA` - Data center for the European Union, Middle East, and Africa.
Expand Down
5 changes: 4 additions & 1 deletion oss/source/Model/Result.gen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ public Result()
}

/// <summary>
///Gets or Sets _Result
///A human friendly description of the state of processing.
/// </summary>
/// <value>
///A human friendly description of the state of processing.
/// </value>
[DataMember(Name="result", EmitDefaultValue=false)]
public string _Result { get; set; }

Expand Down
3 changes: 2 additions & 1 deletion oss/source/custom-code/IOSSFileTransfer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using System.Net.Http;
using System.Threading.Tasks;
using System.Threading;
using System.IO;
namespace Autodesk.Oss
{
public interface IOSSFileTransfer
Expand All @@ -31,7 +32,7 @@ public interface IOSSFileTransfer
Task<HttpResponseMessage> Upload(
string bucketKey,
string objectKey,
string sourceToUpload,
Stream sourceToUpload,
string accessToken,
CancellationToken cancellationToken,
string projectScope = "",
Expand Down
22 changes: 8 additions & 14 deletions oss/source/custom-code/OSSFileTransfer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,27 +92,25 @@ public OSSFileTransfer(IFileTransferConfigurations configuration,
_authentication = authentication;
}

private async Task<bool> IsFileSizeAllowed(string filePath)
private async Task<bool> IsFileSizeAllowed(Stream filePath)
{
return await Task.Run(() =>
{
using (FileStream fileStream = File.OpenRead(filePath))
{
long fileSize = fileStream.Length;

long fileSize = filePath.Length;
double numberOfChunks = CalculateNumberOfChunks((ulong)fileSize);
if (numberOfChunks > this._maxChunkCountAllowed)
{
return false;
}
}
return true;
});
}

public async Task<HttpResponseMessage> Upload(
string bucketKey,
string objectKey,
string sourceToUpload,
Stream sourceToUpload,
string accessToken,
CancellationToken cancellationToken,
string projectScope = "",
Expand All @@ -128,10 +126,7 @@ public async Task<HttpResponseMessage> Upload(
ValidateProjectScopeName(requestId, projectScope);

progress?.Report(1);

using (FileStream fileStream = File.OpenRead(sourceToUpload))
{
ulong numberOfChunks = (ulong)CalculateNumberOfChunks((ulong)fileStream.Length);
ulong numberOfChunks = (ulong)CalculateNumberOfChunks((ulong)sourceToUpload.Length);
ulong chunksUploaded = 0;

long start = 0;
Expand All @@ -140,15 +135,15 @@ public async Task<HttpResponseMessage> Upload(

_logger.LogInformation("{requestId} Total chunk to be uploaded: {numberOfChunks}", requestId, numberOfChunks);

using (BinaryReader reader = new BinaryReader(fileStream))
using (BinaryReader reader = new BinaryReader(sourceToUpload))
{
while (chunksUploaded < numberOfChunks)
{
ThrowIfCancellationRequested(cancellationToken, requestId);

int attempts = 0;

long end = Math.Min((long)((chunksUploaded + 1) * Constants.ChunkSize), fileStream.Length);
long end = Math.Min((long)((chunksUploaded + 1) * Constants.ChunkSize), sourceToUpload.Length);
byte[] fileBytes = readFileBytes(reader, start, end);

var retryUrlExpiryCount = 0;
Expand Down Expand Up @@ -237,7 +232,6 @@ public async Task<HttpResponseMessage> Upload(

progress?.Report(100);
return completeResponse;
}
}

private byte[] readFileBytes(BinaryReader reader, long start, long end)
Expand Down Expand Up @@ -460,7 +454,7 @@ private async Task<ApiResponse<Signeds3downloadResponse>> GetS3SignedDownloadUrl
throw new OssApiException($"{requestId} Failed to get download urls after maximum retry.");
}

private async Task ValidateFileSize(string requestId, string sourceToUpload)
private async Task ValidateFileSize(string requestId, Stream sourceToUpload)
{
var sizeAllowed = await IsFileSizeAllowed(sourceToUpload);
if (!sizeAllowed)
Expand Down
Loading

0 comments on commit 19319c3

Please sign in to comment.