The code runs on my own nodejs server
Error: Request failed with status code 400 when reply image message.
[root@dft-lab5 line]# node line.js
listening on 3000
downloadPath: /home/260im/line/downloaded/8176050397203.jpg
{ Error: Request failed with status code 400
at wrapError (/home/260im/line/node_modules/@line/bot-sdk/dist/http.js:10:15)
at
at process._tickCallback (internal/process/next_tick.js:188:7)
statusCode: 400,
statusMessage: 'Bad Request',
originalError:
{ Error: Request failed with status code 400
at createError (/home/260im/line/node_modules/@line/bot-sdk/node_modules/axios/lib/core/createError.js:16:15)
at settle (/home/260im/line/node_modules/@line/bot-sdk/node_modules/axios/lib/core/settle.js:18:12)
at IncomingMessage.handleStreamEnd (/home/260im/line/node_modules/@line/bot-sdk/node_modules/axios/lib/adapters/http.js:191:11)
at emitNone (events.js:111:20)
at IncomingMessage.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
config:
{ adapter: [Function: httpAdapter],
transformRequest: [Object],
transformResponse: [Object],
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
validateStatus: [Function: validateStatus],
headers: [Object],
method: 'post',
url: 'https://api.line.me/v2/bot/message/reply',
data: '{"messages":[{"type":"image","originalContentUrl":"/home/260im/line/downloaded/8176050397203.jpg","previewImageUrl":"/home/260im/line/downloaded/8176050397203.jpg"}],"replyToken":"db9227714g3ercdf402ca1cbe24f1b702065"}' },
request:
ClientRequest {
domain: null,
_events: [Object],
_eventsCount: 6,
_maxListeners: undefined,
output: [],
outputEncodings: [],
outputCallbacks: [],
outputSize: 0,
writable: true,
_last: true,
upgrading: false,
chunkedEncoding: false,
shouldKeepAlive: false,
useChunkedEncodingByDefault: true,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: null,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
socket: [Object],
connection: [Object],
_header: 'POST /v2/bot/message/reply HTTP/1.1\r\nAccept: application/json, text/plain, /\r\nContent-Type: application/json\r\nAuthorization: Bearer Tvys+4/cXSwidwlogmK9hZSruhRefkyEwUuoRm3sIUFf1ywzyPFV/LcxqkKkJwmpRW7XKvz8c1Cyt1KyF00GSmYzCeGo54sOfVaFCwtgwHyUQ77TNm3rgYnM1PZvPwQTfu5QMLuB/y/9aNUOYDfj3wdB04t89/1O/w1cDnyilFU=\r\nUser-Agent: @line/bot-sdk/6.1.0\r\nContent-Length: 214\r\nHost: api.line.me\r\nConnection: close\r\n\r\n',
_onPendingData: [Function: noopPendingOutput],
agent: [Object],
socketPath: undefined,
timeout: undefined,
method: 'POST',
path: '/v2/bot/message/reply',
_ended: true,
res: [Object],
aborted: undefined,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
_redirectable: [Object],
[Symbol(outHeadersKey)]: [Object] },
response:
{ status: 400,
statusText: 'Bad Request',
headers: [Object],
config: [Object],
request: [Object],
data: [Object] } } }
===== the source code ========
function downloadContent(messageId) {
const downloadPath = path.join(rootPath, 'downloaded', ${messageId}.jpg
);
return client.getMessageContent(messageId)
.then((stream) => new Promise((resolve, reject) => {
const writable = fs.createWriteStream(downloadPath);
stream.pipe(writable);
stream.on('end', () => resolve(downloadPath));
stream.on('error', reject);
}));
};
function handleImage(message, replyToken,source) {
return downloadContent(message.id)
.then((downloadPath) => {
// ImageMagick is needed here to run 'convert'
// Please consider about security and performance by yourself
// cp.execSync(convert -resize 240x jpeg:${downloadPath} jpeg:${previewPath}
);
//
console.log("downloadPath:",downloadPath);
return client.replyMessage(
replyToken,
{
type : 'image',
originalContentUrl: rootPath + '/downloaded/' + path.basename(downloadPath),
previewImageUrl : rootPath + '/downloaded/' + path.basename(downloadPath),
}
);
}