-
Notifications
You must be signed in to change notification settings - Fork 862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TransferUtilityUploadRequest.UploadProgressEvent event not firing #3308
Comments
@Abhiram-Kasu Good morning. Could you please share the following:
Thanks, |
Hello @ashishdhingra, The size of the file that I am trying to upload is 12 mb, but I also have tried with bigger and smaller files The source of the stream is from an IBrowserFile and from calling the OpenReadStream(); await using var stream = file.OpenReadStream(MAX_FILE_SIZE); As for trying to upload with a file, it does work when I copy the full file to the server, but it is not feasible for my blazor application as the file sizes can vary and grow. Is there a way for me to achieve progress updates with a stream without copying the full file to the server? |
@Abhiram-Kasu We would need to investigate. So are you executing S3 upload using TransferUtility from the Blazor client side code? Could you check in .NET code, what is the value of |
Reproducible using code below: long MEG_SIZE = (int)Math.Pow(2, 20);
var fileName = GenerateName(@"SimpleUploadTest\SmallFile");
var path = Path.Combine(Path.GetTempPath(), fileName);
var fileSize = 20 * MEG_SIZE;
GenerateFile(path, fileSize);
//take the generated file and turn it into an unseekable stream
var stream = GenerateBrowserFileUnseekableStreamFromFile(path);
using (var tu = new Amazon.S3.Transfer.TransferUtility(client))
{
TransferUtilityUploadRequest transferUtilityUploadRequest = new TransferUtilityUploadRequest()
{
BucketName = bucketName,
Key = fileName,
InputStream = stream
};
transferUtilityUploadRequest.UploadProgressEvent += (object? sender, UploadProgressArgs e) => Console.WriteLine($"Progress: {e.PercentDone}");
transferUtilityUploadRequest.Metadata.Add("testmetadata", "testmetadatavalue");
transferUtilityUploadRequest.Headers["Content-Disposition"] = "attachment; filename=\"" + fileName + "\"";
tu.Upload(transferUtilityUploadRequest);
}
BrowserFileUnseekableStream GenerateBrowserFileUnseekableStreamFromFile(string filePath)
{
try
{
BrowserFileUnseekableStream unseekableStream = new BrowserFileUnseekableStream(filePath);
return unseekableStream;
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred while generating the stream: {ex.Message}");
throw;
}
}
static string GenerateName(string name)
{
return name + new Random().Next();
}
static void GenerateFile(string path, long size)
{
string contents = GenerateTestContents(size);
WriteFile(path, contents);
}
static void WriteFile(string path, string contents)
{
string fullPath = Path.GetFullPath(path);
new DirectoryInfo(Path.GetDirectoryName(fullPath)).Create();
File.WriteAllText(fullPath, contents);
}
static string GenerateTestContents(long size)
{
StringBuilder sb = new StringBuilder();
for (long i = 0; i < size; i++)
{
char c = (char)('a' + (i % 26));
sb.Append(c);
}
string contents = sb.ToString();
return contents;
}
public class BrowserFileUnseekableStream : MemoryStream
{
MemoryStream inner;
public BrowserFileUnseekableStream(string path)
{
this.inner = new MemoryStream(File.ReadAllBytes(path));
}
public override bool CanSeek
{
get => false;
}
public override long Length
{
get
{
if (inner.Length >= -1)
{
return inner.Length;
}
throw new NotSupportedException();
}
}
} Needs review with the team. Based on user provided screenshot in #3308 (comment), |
@Abhiram-Kasu Hello, I've been trying to reproduce the scenario where you said it did work. You mentioned versions 3.7.0? Can you give me the exact version and maybe attach some logs for me to look at? I created a wrapper around the FileStream class where it wasn't seekable but did contain a content length. I tried to upload via the TransferUtility with version 3.7.0 and the upload wasn't even going through in those cases, so I'm curious how it was working in the previous versions. When that didn't work I tried to use a Blazor app, using a BrowserFileStream and it threw this error at me:
Unseekable stream upload support was added in the last year or so, so the reason the delegates aren't being called now is because it's going through a different code path. We could add some progress handlers but first I want to make sure that it was working before and perhaps just route it to the previous code path where it was working. |
Sorry for no response, glad to see you can reproduce. I did in fact just use version 3.7.0 though. |
@Abhiram-Kasu No problem, the fix for this has been released in AWSSDK.S3 3.7.308.6. Going to close this out now, feel free to re-open if you find something wrong! |
Comments on closed issues are hard for our team to see. |
Describe the bug
Any delegates added to the UploadProgressEvent are not being activated. Files are still uploaded at the end, but callbacks are not being invoked. Tried downgrading sdk version to 3.7.0 and the callbacks DID WORK and were called.
Expected Behavior
Expected delegates to activate to give progress updates on the current file upload request
Current Behavior
Delegates are never called, as in the code inside the event handler is never ran regardless of the file size and the time taken
Reproduction Steps
Create a TransferUtility object
Create TransferUtilityUploadRequest with a file stream and attach handler to the UploadProgressEvent event
await upload
Possible Solution
No response
Additional Information/Context
No response
AWS .NET SDK and/or Package version used
AWSSDK.S3 3.7.307.25
Targeted .NET Platform
.NET 8
Operating System and version
Mac OS Sonoma M3 Pro
The text was updated successfully, but these errors were encountered: