mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-22 17:47:53 +00:00
Support streamed response from HttpNodeInstance
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -36,10 +37,10 @@ namespace NodeServicesExamples.Controllers
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
// Invoke Node and convert the base64 result back to bytes
|
||||
// Invoke Node and pipe the result to the response
|
||||
var mimeType = GetContentType(imagePath);
|
||||
var resizedImage = await _nodeServices.Invoke<ResizeImageResult>("./Node/resizeImage", fileInfo.PhysicalPath, mimeType, maxWidth, maxHeight);
|
||||
return File(Convert.FromBase64String(resizedImage.Base64), mimeType);
|
||||
var imageStream = await _nodeServices.Invoke<Stream>("./Node/resizeImage", fileInfo.PhysicalPath, mimeType, maxWidth, maxHeight);
|
||||
return File(imageStream, mimeType);
|
||||
}
|
||||
|
||||
private string GetContentType(string path)
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
var sharp = require('sharp');
|
||||
|
||||
module.exports = function(cb, physicalPath, mimeType, maxWidth, maxHeight) {
|
||||
module.exports = function(result, physicalPath, mimeType, maxWidth, maxHeight) {
|
||||
sharp(physicalPath)
|
||||
.resize(maxWidth > 0 ? maxWidth : null, maxHeight > 0 ? maxHeight : null)
|
||||
.toBuffer(function (err, buffer) {
|
||||
cb(err, { base64: buffer && buffer.toString('base64') });
|
||||
});
|
||||
.pipe(result.stream);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user