kingluo commented on code in PR #9414:
URL: https://github.com/apache/apisix/pull/9414#discussion_r1186599122


##########
docs/en/latest/plugins/grpc-transcode.md:
##########
@@ -102,34 +102,26 @@ The output binary file, `proto.pb` will contain both 
`helloworld.proto` and `imp
 
 We can now use the content of `proto.pb` in the `content` field of the API 
request.
 
-As the content of the proto is binary, we encode it in `base64` using this 
Python script:
-
-```python title="upload_pb.py"
-#!/usr/bin/env python
-# coding: utf-8
-
-import base64
-import sys
-
-# sudo pip install requests
-import requests
-
-if len(sys.argv) <= 1:
-    print("bad argument")
-    sys.exit(1)
-with open(sys.argv[1], 'rb') as f:
-    content = base64.b64encode(f.read())
-id = sys.argv[2]
-api_key = "edd1c9f034335f136f87ad84b625c8f1" # use a different API key
-
-reqParam = {
-    "content": content,
-}
-resp = requests.put("http://127.0.0.1:9180/apisix/admin/protos/"; + id, 
json=reqParam, headers={
-    "X-API-KEY": api_key,
-})
-print(resp.status_code)
-print(resp.text)
+As the content of the proto is binary, we encode it in `base64` using this 
shell script:
+
+```shell
+#!/usr/bin/env bash
+
+set -xeu
+
+if [ $# -lt 2 ]; then
+    echo "usage: $0 <proto_file> <proto_id>"
+    exit 1
+fi
+
+proto_file_name=$1
+id=$2
+api_key=edd1c9f034335f136f87ad84b625c8f1
+
+content=$(base64 -i "$proto_file_name")
+request_body="{\"content\": \"$content\"}"
+
+curl http://127.0.0.1:9180/apisix/admin/protos/"$id"; -X PUT -H "X-API-KEY: 
$api_key" -d "$request_body"

Review Comment:
   No need to use a script, instead, to make full use of bash functionality, 
one command line is enough.
   
   ```bash
   curl http://127.0.0.1:9180/apisix/admin/protos/1 \
   -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
   {
       "content" : "'"$(base64 -w0 /path/to/proto.pb)"'"
   }'
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to