Skip to content
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

Issue with converting to the bytes data type #1781

Closed
holahula opened this issue Oct 29, 2020 · 4 comments
Closed

Issue with converting to the bytes data type #1781

holahula opened this issue Oct 29, 2020 · 4 comments

Comments

@holahula
Copy link

🐛 Bug Report

There is an issue with using a Javascript byte array as the protobuf type bytes.
This is the code used to create the byte array

const b64 = uri.replace('data:image/jpeg;base64,', '');
const byteArray = Array.from(Uint8Array.from(window.atob(b64), c => c.charCodeAt(0)));

To Reproduce

  1. Create sample rpc function + POST annotation that takes a bytes input field in the request message.
  2. Post to the associated REST endpoint with some valid Uint8Array .
  3. Notice error posted below

Expected behavior

Request should succeed.

image
This rpc function succeeds when using a Go gRPC client + []byte as the input field. Thus, I suspect the issue is somewhere before the request reaches the rpc function (in the area handled by grpc-gateway)

Actual Behavior

image

Your Environment

OSX
Go 1.14.2
github.com/grpc-ecosystem/grpc-gateway/v2 v2.0.1

@mog3n
Copy link

mog3n commented Oct 29, 2020

I am having the same issue as well

@johanbrandhorst
Copy link
Collaborator

If you want to receive a bytes type, you have to use the JSON representation of bytes, which is a URL-safe base64 encoding of the bytes, as per the language specification: https://developers.google.com/protocol-buffers/docs/proto3#json.

@veith
Copy link
Contributor

veith commented Dec 23, 2022

What is about google.api.HttpBody or something similar?

It would be very nice if there is a type which can receive raw binary data as body, and all according metadata via headers (Content-Type video/mp4).

Browsers of today can send real binary data (const binaryData = new Uint8Array(buffer);).
Curl scripts also (curl --data-binary "@filepath").

This would reduce the transferred data size by 33%.

I refer to HttpBody, because this type is only usable as a "root" response type in a transcoded context, why not bidirectional?

@johanbrandhorst
Copy link
Collaborator

Seems reasonable to add support for unmarshaling a HTTPBody as raw data. I expect you probably would just update the definition in https://github.com/grpc-ecosystem/grpc-gateway/blob/main/runtime/marshal_httpbodyproto.go. Could you create a separate issue though?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants