से डेटा प्राप्त नहीं कर रहा है, मैं एक सर्वर मार्ग से एक छवि वापस करने का प्रयास कर रहा हूं, लेकिन मुझे 0 बाइट्स मिल रहा है। मुझे संदेह है कि मैं MemoryStream
का उपयोग कैसे कर रहा हूं इसके साथ कुछ करना है। यहाँ मेरी कोड है:मार्ग सी #
[HttpGet]
[Route("edit")]
public async Task<HttpResponseMessage> Edit(int pdfFileId)
{
var pdf = await PdfFileModel.PdfDbOps.QueryAsync((p => p.Id == pdfFileId));
IEnumerable<Image> pdfPagesAsImages = PdfOperations.PdfToImages(pdf.Data, 500);
MemoryStream imageMemoryStream = new MemoryStream();
pdfPagesAsImages.First().Save(imageMemoryStream, ImageFormat.Png);
HttpResponseMessage response = new HttpResponseMessage();
response.Content = new StreamContent(imageMemoryStream);
response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = pdf.Filename,
DispositionType = "attachment"
};
return response;
}
डिबगिंग के माध्यम से मैं सत्यापित किया है कि PdfToImages
विधि काम कर रहा है और वह imageMemoryStream
इसे चलाने में लाइन से डेटा के साथ भर जाता है
pdfPagesAsImages.First().Save(imageMemoryStream, ImageFormat.Png);
हालांकि, मैं एक लगाव है कि प्राप्त ठीक से नामित लेकिन 0 बाइट्स है। पूरी फाइल प्राप्त करने के लिए मुझे क्या बदलने की ज़रूरत है? मुझे लगता है कि यह कुछ आसान है लेकिन मुझे यकीन नहीं है कि क्या। अग्रिम में धन्यवाद।
शायद आपको 0 से स्ट्रीम स्थिति सेट करनी है? 'imageMemoryStream.Position = 0;' –