1 回答

TA貢獻1833條經驗 獲得超4個贊
我決定查看request.Body,似乎通過將其添加*/*到 API 網關二進制媒體類型,現在即使請求也是編碼的,你看第一個字母確實是eas消息說。
所以我改變了這個:
// Unmarshal json request body into a TemplateRendererRequest struct that mimics the json payload
requestData := TemplateRendererRequest{}
err := json.Unmarshal([]byte(request.Body), &requestData)
if err != nil {
return events.APIGatewayProxyResponse{
Body: fmt.Errorf("Error: %s ", err.Error()).Error(),
StatusCode: 400,
Headers: map[string]string{
"Content-Type": "text/plain",
},
}, err
}
對此:
// Unmarshal json request body into a TemplateRendererRequest struct that mimics the json payload
requestData := TemplateRendererRequest{}
b64String, _ := base64.StdEncoding.DecodeString(request.Body)
rawIn := json.RawMessage(b64String)
bodyBytes, err := rawIn.MarshalJSON()
if err != nil {
return events.APIGatewayProxyResponse{
Body: fmt.Errorf("Error: %s ", err.Error()).Error(),
StatusCode: 400,
Headers: map[string]string{
"Content-Type": "text/plain",
},
}, err
}
jsonMarshalErr := json.Unmarshal(bodyBytes, &requestData)
if jsonMarshalErr != nil {
return events.APIGatewayProxyResponse{
Body: fmt.Errorf("Error: %s ", jsonMarshalErr.Error()).Error(),
StatusCode: 400,
Headers: map[string]string{
"Content-Type": "text/plain",
},
}, jsonMarshalErr
}
從我在網上看到的你也可以改變這個:
rawIn := json.RawMessage(b64String)
bodyBytes, err := rawIn.MarshalJSON()
對此:
[]byte(b64String)
當我現在執行 CURL 請求并將其輸出到文件時,我會正確地獲得 PDF。
- 1 回答
- 0 關注
- 119 瀏覽
添加回答
舉報