【问题标题】:Sending two objects as response to a single GET request using Express and Node.js使用 Express 和 Node.js 发送两个对象作为对单个 GET 请求的响应
【发布时间】:2014-07-08 15:06:11
【问题描述】:

我有以下代码 -

sendServer.get('/download',function(request,response){
var status="SELECT * from poetserver.download where status='0'";
console.log(status)
connection.query(status,function(error,rows){
    var toSend=rows[0].id
    response.sendfile('./testimages/'+toSend+'.PNG')
    // var details={"pictureId":toSend}
    // response.writeHead(200, { 'Content-Type': 'application/json' });
    // response.send(JSON.stringify(details)); 

本质上,首先,我想发送一个由 toSend 标识的文件。使用 response.sendFile 成功发送文件。但我也想为客户提供一些文件标识,以供将来回复。我也怎么发送?

【问题讨论】:

标签: javascript node.js express get response


【解决方案1】:

要发送您正在响应的图像(资源)的 id,您应该使用HTTP header,例如ETag。不要尝试在一个响应正文中发送 JSON 和二进制数据。

【讨论】:

    猜你喜欢
    • 2021-08-13
    • 1970-01-01
    • 1970-01-01
    • 2019-03-10
    • 2015-01-16
    • 2020-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多