-
Notifications
You must be signed in to change notification settings - Fork 10.4k
47685 stream to blob #62298
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
Open
MaxxBahr
wants to merge
2
commits into
dotnet:main
Choose a base branch
from
MaxxBahr:47685_StreamToBlob
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
47685 stream to blob #62298
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@dotnet-policy-service agree |
@MaxxBahr could the same be achieved from user code ? The issue speaks about not loading the whole (video) stream into memory at the same time. This PR does load it all. |
@pavelsavara : The design details for the blob() method are outlined in the related design proposal #61826. |
Commenter does not have sufficient privileges for PR 62298 in repo dotnet/aspnetcore |
/azp run |
Commenter does not have sufficient privileges for PR 62298 in repo dotnet/aspnetcore |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
area-blazor
Includes: Blazor, Razor Components
community-contribution
Indicates that the PR has been added by a community member
pending-ci-rerun
When assigned to a PR indicates that the CI checks should be rerun
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add blob() method to JS side of Blazor DotNetStreamReference
Added method readableStreamToBlob() which returns a Blob from the given stream.
Description
The readableStreamToBlob method is an asynchronous function defined on the internal DotNetStream class. Its purpose is to convert a JavaScript ReadableStream (typically received from .NET interop) into a Blob URL that can be used in browser APIs (such as for downloads or displaying media).
Step-by-step Description
Obtain a Stream Reader:
The function first awaits the result of this.stream(), which returns a ReadableStream. It then calls .getReader() on this stream to obtain a reader for consuming the stream's data chunks.
Read All Chunks:
It initializes an empty array called chunks. Using a while (true) loop, it repeatedly calls reader.read(), which returns a promise resolving to an object with { done, value }.
If done is true, the stream has ended and the loop breaks.
Otherwise, it pushes the value (a chunk of data, typically a [Uint8Array]) into the [chunks] array.
Create a Blob:
After reading all chunks, it creates a new [Blob] from the collected [chunks] array. The mimeType parameter (defaulting to "application/octet-stream") is used as the Blob's type.
Create a Blob URL:
It then calls URL.createObjectURL(blob) to generate a temporary URL representing the Blob's data in memory.
Return the URL:
The function returns this Blob URL as a string. This URL can be used in browser contexts to reference the streamed data (for example, as a download link or image source).
Fixes #47685