-
Notifications
You must be signed in to change notification settings - Fork 782
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
Usage demo about how to upload file/image by grpc-web? #517
Comments
Neither gRPC or gRPC-Web is designed for being used as a file upload
frameworks. Just RPC.
That being said, Google does something that may interest you, create an
method on the server-side which returns an URL that can be used to upload
octet streams by using plain old HTTP. If you want to go further you can
even use TUS on that endpoint:
https://tus.io/.
…On Sat, 23 Mar 2019 at 07:50, Daniel Zhang ***@***.***> wrote:
Anybody know how to upload file/image by grpc-web?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#517>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACIPlgz4w6vIi0H5voKsvORXmcqtv6Wiks5vZc64gaJpZM4cEwRU>
.
|
bytes field seems to be a workaround, but it is only for small file. |
The closest you could get to a pure GRPC solution would be a client-streaming API where you send up chunks of the image file at a time. Unfortunately that's not possible since GRPC-Web doesn't yet support client streaming. However, the https://github.com/improbable-eng/grpc-web/ implementation does support it, by using WebSockets. That's one option to pursue. |
File upload is not a main use case for gRPC or gRPC-Web. There are standard HTTP way of doing file uploads. |
Using plain HTTP in a system that all of it's APIs are GRPC based makes thing a little messy. Is there a fundamental reason that you're suggesting plain HTTP over GRPC? I think for small files (e.g. image files) it's possible to put the whole file inside a bytes field and send it to the server using a simple rpc, do you think it's a bad idea? |
My app does use the HTML FileReader API to load a file into a string which is then wrapped with a GRPC message. It works, but only for smaller files (fine my my case). |
How small a file? My understanding is that string size is 64 bits, but GRPC puts a 64MB limit on the message itself. |
grpc-web now supports streaming .. you can try sending files in chunk. I have done similar in dart grpc-web |
I came across this post multiple times when I try to have a simple file uploader implemented via web-grpc. and I didnt want to implement another endpoint for uploading data @stanley-cheung "the standard way". So i implemented yesterday following idea General idea: 1. chunk the files in browser, 2. upload them in pieces, 3. merge them in the backend [. .proto file] by using another method
[.js file] first some "global" component variables. (see later in script by using variable with "this")
and now the different function to handle all the pieces:
[.go file]
especially timeouts should be handled and tested carefully as it also depends on the users bandwidth... P.S. if anyone got a solution how to provide downloads in the browser using the server side streaming functionality - let me know PPS. a fork of https://github.com/23/resumable.js would provide a more solid frontend solution with nice additional features. "just" the xhr part needs to be replace somehow by the grpc functionalities... PPPS. perhaps some skilled js people can help to actually merge the chunk reader and upload part together, as the current bottle neck is that all chunks got sent one after another - better would be to wait, e.g 1. read first chunk, wait for file reader callback, 2. upload chunk via grpc, 3. wait for upload callback, continue chunking.... |
@maltegrosse The example is so complicated 😭 |
For others reading this, creating a signed URL for uploading a file to a bucket and sending that URL over the gRPC connection is the way I plan to handle this: https://cloud.google.com/storage/docs/access-control/signed-urls Or, alternatively, just handle this with resumable uploads. Initialising the upload server side, and then passing through the required session URI to complete the upload client side: |
Anybody know how to upload file/image by grpc-web?
The text was updated successfully, but these errors were encountered: