[英]How to get jpg file from CloudFiles on Rackspace using openstack.net
I'm running the below code in my controller in an asp.net mvc project. 我在asp.net mvc项目的控制器中运行以下代码。 I want to enable the user to view or download the files that I store on Cloud Files on rackspace.
我想让用户查看或下载我在rackspace上存储的文件。
var identity =
new CloudIdentity()
{
Username = "username",
APIKey = "apikey"
};
var storage = new CloudFilesProvider(identity);
Stream jpgStream = new MemoryStream();
storage.GetObject("files.container", "1.jpg", jpgStream);
Stream pdfStream = new MemoryStream();
storage.GetObject("files.container", "2.pdf", pdfStream);
var jpgResult = File(jpgStream, "Image/jpg", "1.jpg");
var pdfResult = File(pdfStream, "Application/pdf", "2.pdf");
The above code works when I return pdfResult. 当我返回pdfResult时,上面的代码有效。 I get the correct file.
我得到了正确的文件。 But when I return the jpgResult, the browser downloads 1.jpg as an empty 0KB file.
但是当我返回jpgResult时,浏览器将1.jpg作为空的0KB文件下载。
Am I doing this the right way? 我这样做是对的吗? Any idea what the problem might be?
知道问题可能是什么?
Problem solved after I added: 我添加后问题解决了:
jpgStream.Position = 0;
pdfStream.Position = 0;
Before the File() call. 在File()调用之前。 As per the question: File is empty and I don't understand why.
根据问题: 文件是空的,我不明白为什么。 Asp.net mvc FileResult
Asp.net mvc FileResult
I don't know why this wasn't an issue with the pdf file. 我不知道为什么这不是pdf文件的问题。
您还可以使用GetObjectSaveToFile方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.