【问题标题】:Azure blobs and thumbnailsAzure blob 和缩略图
【发布时间】:2011-04-13 07:21:53
【问题描述】:

我有两张图片 clear.jpg 和 thumbclear.jpg,第二张是我的缩略图 使用以下代码从第一个创建: 我还没有调整大小

  Bitmap bitmap = new Bitmap(File.InputStream);
  MemoryStream st = new MemoryStream();
  try
  {
     bitmap.Save(st, ImageFormat.Png);
     return st;
  }
  finally
  {
     bitmap.Dispose();
  }

然后我将两个图像都上传到 blob,然后获取它们的 URI 并将它们复制/粘贴到 浏览器。 第一个 http://127.0.0.1:10000/devstoreaccount1/media/e1a987d1-c731-4e26-9e6c-d7a63b62f661/clear.png 工作正常,

但是第二个http://127.0.0.1:10000/devstoreaccount1/media/b7ba6428-9db4-4282-8991-7a8198e7126f/thumbclear.png 给我以下错误:

图片“http://...thumbclear.png”无法显示,因为它包含错误。

所以我认为它与要流式传输的位图有关。 任何帮助将不胜感激。

**编辑 我用来保存 blob 的代码

public static CloudBlob SaveFileToBlob(MemoryStream stream, string blobContainerName, string filename, string extension, string contentType, int fileSize)
        {
            if (stream != null)
            {
                CloudBlobContainer _BlobContainer = SessionHelper.GetBlobContainer(blobContainerName);
                var permissions = new BlobContainerPermissions();
                permissions.PublicAccess = BlobContainerPublicAccessType.Container;
                _BlobContainer.SetPermissions(permissions);

                Guid blobid = Guid.NewGuid();
                var blob = _BlobContainer.GetBlobReference(blobid.ToString() + "/" + filename);
                blob.UploadFromStream(stream);

                blob.Metadata["FileName"] = filename;
                blob.Metadata["Extension"] = extension;
                blob.Metadata["FileSize"] = fileSize.ToString();
                blob.SetMetadata();

                blob.Properties.ContentType = contentType;
                blob.SetProperties();

                return blob;
            }
            else
                return null;
        }

【问题讨论】:

  • 感谢 zynaps - 请提供此评论作为答案,或删除问题。
  • 还要确保流被关闭和处理

标签: c# asp.net-mvc azure


【解决方案1】:

解决方案是在上传到 blob 之前将流位置设置为零。

stream.Position = 0;
blob.UploadFromStream(stream);

【讨论】:

    【解决方案2】:

    对于第一个样本:

      Bitmap bitmap = new Bitmap(File.InputStream);
      MemoryStream st = new MemoryStream();
      try
      {
         bitmap.Save(st, ImageFormat.Png);
    
    
    //worked for me
            Response.ContentType = "image/png";
            st.WriteTo(Response.OutputStream);
    //--
    
    
      }
      finally
      {
         bitmap.Dispose();
      }
    

    而且,我今天找到了

    Function Index() As FileContentResult
        Dim Resim = New WebClient().DownloadData("https://dosyalar.blob.core.windows.net/dosya/kartalisveris.gif")
        Return New FileContentResult(Resim, "image/png") '* With {.FileDownloadName = "Höbölö"}
    End Function
    

    【讨论】:

      猜你喜欢
      • 2016-10-15
      • 1970-01-01
      • 2016-03-04
      • 2018-09-04
      • 2015-07-28
      • 2014-05-22
      • 1970-01-01
      • 2015-06-01
      • 1970-01-01
      相关资源
      最近更新 更多