在此发布请求中,有一个json正文,其中包含base64编码的数据(zip文件),如以下示例所示:
{ “ foo”:“ bar”, “ data”:“您的base64字符串” }
在API策略中,我想向Azure存储REST API发送一个单独的请求,以将上述base64字符串另存为zip文件。
现在的问题是: 我可以成功将请求发送到Azure存储REST API,并通过以下语句下载生成的zip文件:
df.A.gt(df.B).view('i1').diff().fillna(0, downcast = 'i1')
0 0
1 -1
2 0
3 1
dtype: int8
问题是,我可以下载并打开zip文件,但是由于存档损坏,我无法提取其中的内容。
这是一个示例base64编码的zip文件字符串(包含text.txt的ZIP文件):
<set-body>@{
var base64String = (string)context.Variables.GetValueOrDefault<JObject>("body")["data"]) ;
var bytes = Convert.FromBase64String(base64String);
var ascii = Encoding.ASCII.GetString(bytes);
return ascii;
}</set-body>
这是我将其发布到Rest API的代码:
UEsDBBQAAAAIAL1ZxE7MTbG/EwAAABMAAAAIAAAAdGVzdC50eHQLycgsVgCiRIWS1OKStMycVD0AUEsBAh8AFAAAAAgAvVnETsxNsb8TAAAAEwAAAAgAJAAAAAAAAAAgAAAAAAAAAHRlc3QudHh0CgAgAAAAAAABABgAI8Ac2LUa1QEjwBzYtRrVAZFuI861GtUBUEsFBgAAAAABAAEAWgAAADkAAAAAAA==
答案 0 :(得分:2)
Azure API管理现在在正文中支持byte []:
https://azure.microsoft.com/en-us/updates/azure-api-management-update-september-2019
set-body策略还接受字节数组作为正文内容。
通过在Blob-Storage中创建一个zip文件,下载,打开该zip文件并打开包含的文本文件,我的测试成功了。
使用了以下代码:
const pollQuestion = props => (<div>{props.quest}</div>);
我只需要删除:
//imports
import Poll from 'react-polls';
const pollQuestion = props => (<div>{props.quest}</div>);
const pollAnswers = [
{ option: 'Yes', votes: 8 },
{ option: 'No', votes: 2 }
]
class PollQuestion extends Component {
state = {
pollAnswers: [...pollAnswers]
}
handleVote = voteAnswer => {
const { pollAnswers } = this.state
const newPollAnswers = pollAnswers.map(answer => {
if (answer.option === voteAnswer) answer.votes++
return answer
})
this.setState({
pollAnswers: newPollAnswers
})
}
render () {
const { pollAnswers } = this.state
return (
<div>
<Poll question={pollQuestion} answers={pollAnswers} onVote={this.handleVote} />
<p>It works</p>
</div>
);
}
};
class QuestionList extends Component {
state = {
questions: []
}
componentDidMount(){
this.setState({ questions: [{question_text:'123'}]});
}
render(){
return (
<div>{this.state.questions?
<ul>
<PollQuestion quest={this.state.questions.slice(0, 1).map(question => <li>{question.question_text}</li>)} />
</ul>:null}
</div>
)
}
};
function AppV() {
return (
<div className="App">
<QuestionList/>
</div>
);
}
export default AppV;