我正在尝试从数据库中获取 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);
}