此 WCF 服务返回 TIFF 图像。它检查它是否连接到我们的存储库 - 并从数据文件中获取字节。它检查文件是 PDF、tiff 还是图像,并返回适当的 mime 类型。我现在可以调用该服务,它会返回适当的文件——但图像名称为“documentID”.tif。如何设置它返回的图像的文件名?
[OperationContract]
[WebInvoke(Method = "GET", UriTemplate="File/{documentID}")]
Stream GetDocumentFile_GET(string documentID);
public Stream GetDocumentFile_GET(string documentID)
{
if (ProprietaryClass.IsConnected)
{
ProprietaryClass _documentForViewer = new ProprietaryClass(documentID);
string _fileType = ProprietaryClass.NativeFileType;
string _mimetype = "image/tiff";
switch (_fileType)
{
case "TIF":
_mimetype = "image/tiff";
break;
case "PDF":
_mimetype = "application/pdf";
break;
case "PNG":
_mimetype = "image/png";
break;
};
if (ProprietaryClass.ProprietaryMethod(_documentForViewer))
{
ProprietaryClass _downloadToViewer = new ProprietaryClass();
if (_documentForViewer.TiffFile != null)
{
_downloadToViewer = _documentForViewer.TiffFile;
}
else
{
_downloadToViewer = _documentForViewer.NativeFile;
}
MemoryStream fileStream = new MemoryStream(_downloadToViewer.FileData);
// fileStream is now array of bytes
System.ServiceModel.Web.WebOperationContext.Current.OutgoingResponse.ContentType = _mimetype;
return (Stream)fileStream;
}
else
{
return new MemoryStream(Encoding.UTF8.GetBytes("Document type not supported by native viewer"));
}
}
else
{
return new MemoryStream(Encoding.UTF8.GetBytes("Not connected"));
}
}