Skip to content

Commit

Permalink
fix: missing boundary in response headers
Browse files Browse the repository at this point in the history
fix: multipart not end with CRLF
  • Loading branch information
Chinlinlee committed Oct 5, 2021
1 parent 0364acd commit 06312ef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
28 changes: 15 additions & 13 deletions api/dicom-web/controller/wado-rs.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ module.exports = async function (req , res) {
return sendNotSupportMessage(req ,res);
}
try {
res.set("content-type" , `multipart/related; type="${type}"`);
let resWriteStatus = await multipartFunc[type][getFunc](req.params , res , type);
if (resWriteStatus) {
res.end();
Expand Down Expand Up @@ -218,15 +217,16 @@ let multipartFunc = {
let imagesPath = await mongoFunc.getStudyImagesPath(iParam);
if (imagesPath) {
const BOUNDARY = `${uuid.v4()}-${uuid.v4()}`;
res.set("content-type", `multipart/related; type="${type}"; boundary=${BOUNDARY}`);
for (let i= 0 ; i < imagesPath.length ; i++) {
console.log(`${process.env.DICOM_STORE_ROOTPATH}${imagesPath[i]}`);
let fileBuffer = await streamToBuffer(fs.createReadStream(`${process.env.DICOM_STORE_ROOTPATH}${imagesPath[i]}`));
res.write(`${i==0? "":"\n\n"}--${BOUNDARY}\n`);
res.write(`Content-Type: ${type}\n`);
res.write('Content-length: ' + fileBuffer.length + '\n\n');
res.write(`${i==0? "":"\r\n\r\n"}--${BOUNDARY}\r\n`);
res.write(`Content-Type: ${type}\r\n`);
res.write('Content-length: ' + fileBuffer.length + '\r\n\r\n');
res.write(fileBuffer);
}
res.write(`\n--${BOUNDARY}--`);
res.write(`\r\n--${BOUNDARY}--`);
return resolve(true);
}
return resolve(false);
Expand All @@ -237,15 +237,16 @@ let multipartFunc = {
let imagesPath = await mongoFunc.getSeriesImagesPath(iParam);
if (imagesPath) {
const BOUNDARY = `${uuid.v4()}-${uuid.v4()}`;
res.set("content-type", `multipart/related; type="${type}"; boundary=${BOUNDARY}`);
for (let i= 0 ; i < imagesPath.length ; i++) {
console.log(`${process.env.DICOM_STORE_ROOTPATH}${imagesPath[i]}`);
let fileBuffer = await streamToBuffer(fs.createReadStream(`${process.env.DICOM_STORE_ROOTPATH}${imagesPath[i]}`));
res.write(`${i==0? "":"\n\n"}--${BOUNDARY}\n`);
res.write(`Content-Type: ${type}\n`);
res.write('Content-length: ' + fileBuffer.length + '\n\n');
res.write(`${i==0? "":"\r\n\r\n"}--${BOUNDARY}\r\n`);
res.write(`Content-Type: ${type}\r\n`);
res.write('Content-length: ' + fileBuffer.length + '\r\n\r\n');
res.write(fileBuffer);
}
res.write(`\n--${BOUNDARY}--`);
res.write(`\r\n--${BOUNDARY}--`);
return resolve(true);
}
return resolve(false);
Expand All @@ -256,13 +257,14 @@ let multipartFunc = {
let imagesPath = await mongoFunc.getInstanceImagePath(iParam);
if (imagesPath) {
const BOUNDARY = `${uuid.v4()}-${uuid.v4()}`;
res.set("content-type", `multipart/related; type="${type}"; boundary=${BOUNDARY}`);
let fileBuffer = await streamToBuffer(fs.createReadStream(`${process.env.DICOM_STORE_ROOTPATH}${imagesPath[0]}`));
console.log(imagesPath[0]);
res.write(`--${BOUNDARY}\n`);
res.write(`Content-Type: ${type}\n`);
res.write('Content-length: ' + fileBuffer.length + '\n\n');
res.write(`--${BOUNDARY}\r\n`);
res.write(`Content-Type: ${type}\r\n`);
res.write('Content-length: ' + fileBuffer.length + '\r\n\r\n');
res.write(fileBuffer);
res.write(`\n--${BOUNDARY}--`);
res.write(`\r\n--${BOUNDARY}--`);
return resolve(true);
}
return resolve(false);
Expand Down
1 change: 1 addition & 0 deletions models/DICOMWeb/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ async function writeImageMultipart (res , imagesPath , type) {
}
async function writeframesMultipart (req , res , imagesPath ,type , frameList) {
const BOUNDORY = `${uuid.v4()}-${uuid.v4()}`;
res.set('content-type', `multipart/related; type=${type};boundary=${BOUNDORY}`);
let images = `${process.env.DICOM_STORE_ROOTPATH}${imagesPath[0]}`;
let jpegFile = images.replace(/\.dcm\b/gi , "");
let minFrameNumber = _.min(frameList);
Expand Down

0 comments on commit 06312ef

Please sign in to comment.