3

我正在尝试从数据库中获取 blob,但有时我会收到错误“无效参数”

在这一行

System.Drawing.Image objimg = System.Drawing.Image.FromStream(blobstream, true);

这是我的代码:

public partial class showblob : System.Web.UI.Page
{

     private System.Drawing.Image.GetThumbnailImageAbort delegateabort;
     protected void Page_Load(object sender, EventArgs e)
     {
         // Get a handle on account, create a blob service client and get container proxy
         var account = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("Conn"));
         account.CreateCloudTableClient().CreateTableIfNotExist("tablename");
         var client = account.CreateCloudBlobClient();
         CloudBlobContainer container = client.GetContainerReference("tablename");
         string id = Request["id"].ToString();

         // Retrieve reference to a blob named "myblob"
         CloudBlob blob = container.GetBlobReference(id);
         BlobStream blobstream = blob.OpenRead();

         if (Request["imgvd"] == "0")
         {
             Response.ContentType = "image/jpeg";
             System.Drawing.Image objimg = System.Drawing.Image.FromStream(blobstream, true);

             if (Request["thumb"] != null)
                 objimg = objimg.GetThumbnailImage(140, 210, delegateabort, System.IntPtr.Zero);

             objimg.Save(Response.OutputStream, ImageFormat.Jpeg);
         }

并存储图像,因为我已经使用此方法添加:

if (fileFoto.HasFile)

     try
     {
         CloudBlobClient blobClient = account.CreateCloudBlobClient();
         // Retrieve a reference to a container 
         CloudBlobContainer container = blobClient.GetContainerReference("tablename");
         // Create the container if it doesn't already exist
         container.CreateIfNotExist();
         CloudBlob blob = container.GetBlobReference("c" + ViewState["id"].ToString());               
         blob.UploadFromStream(fileFoto.PostedFile.InputStream);
     }
4

1 回答 1

0

我解决了我的问题。问题是我将参考设置为

CloudBlob blob = container.GetBlobReference("c" + ViewState["id"].ToString());

当我上传照片并使用

CloudBlob blob = container.GetBlobReference(ViewState["id"].ToString());
于 2013-05-14T15:23:45.887 回答