I would like to download a file from s3 with pause and resume functionality using AmazonS3Client.
The code I currently have is:
public async Task<IExternalApiResult<Stream>> DownloadFileWithPauseAndResume(string fileUrl, StorageSource source, int chunkNumber)
{
const int chunkSize = 1024;
var bucket = GetBucketName(source);
var objectName = GetObjectNameFromURL(fileUrl);
if (objectName == null)
return Error<Stream>("File URL is not in a valid format for this storage service");
try
{
var request = new GetObjectRequest();
request.BucketName = bucket;
request.Key = objectName;
var start = chunkNumber * chunkSize + 1;
request.ByteRange = new ByteRange(start, chunkSize);
var result = await s3.GetObjectAsync(request);
await Console.Out.WriteLineAsync(result.ResponseStream.Length.ToString());
return Success(result.ResponseStream);
}
catch (Exception e)
{
return Error<Stream>(e);
}
}
Is this method correct? Also how would I trigger the pause method in this and resume method. Aslo should this method be called with a multiplart HttpGet method from the client(Angular)?