本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.UploadFromStream方法的典型用法代码示例。如果您正苦于以下问题:C# CloudBlockBlob.UploadFromStream方法的具体用法?C# CloudBlockBlob.UploadFromStream怎么用?C# CloudBlockBlob.UploadFromStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob
的用法示例。
在下文中一共展示了CloudBlockBlob.UploadFromStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main(string[] args)
{
Console.WriteLine("Press any key to run sample...");
Console.ReadKey();
// Make sure the endpoint matches with the web role's endpoint.
var tokenServiceEndpoint = ConfigurationManager.AppSettings["serviceEndpointUrl"];
try
{
var blobSas = GetBlobSas(new Uri(tokenServiceEndpoint)).Result;
// Create storage credentials object based on SAS
var credentials = new StorageCredentials(blobSas.Credentials);
// Using the returned SAS credentials and BLOB Uri create a block blob instance to upload
var blob = new CloudBlockBlob(blobSas.BlobUri, credentials);
using (var stream = GetFileToUpload(10))
{
blob.UploadFromStream(stream);
}
Console.WriteLine("Blob uplodad successful: {0}", blobSas.Name);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.WriteLine();
Console.WriteLine("Done. Press any key to exit...");
Console.ReadKey();
}
示例2: Run
public void Run()
{
var storageAccount = CloudStorageAccount.Parse(_storageConnectionString);
var blobClient = storageAccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference("mycontainer");
container.CreateIfNotExists();
_blob = container.GetBlockBlobReference("myblob.txt");
if (!_blob.Exists())
{
using (var s = new MemoryStream())
{
_blob.UploadFromStream(s);
}
}
Task.Factory.StartNew(() => GenerateContentAsync());
Task.Factory.StartNew(() => AppendStreamToBlobAsync());
Task.WaitAll();
}
示例3: OnExecuting
protected override void OnExecuting(CloudBlockBlob workItem)
{
if (workItem == null)
throw new ArgumentNullException("workItem");
if (workItem.Metadata.ContainsKey(CompressedFlag))
return;
using (var blobStream = new MemoryStream())
{
workItem.DownloadToStream(blobStream);
using (var compressedStream = new MemoryStream())
{
CompressStream(compressedStream, blobStream);
SetCompressedFlag(workItem);
workItem.UploadFromStream(compressedStream);
}
}
}
示例4: UploadBlobStream
/// <summary>
/// Uploads Memory Stream to Blob
/// </summary>
/// <param name="outputBlob"></param>
/// <param name="line"></param>
private static void UploadBlobStream(CloudBlockBlob outputBlob, string line)
{
using (MemoryStream ms = new MemoryStream())
{
if (outputBlob.Exists())
{
outputBlob.DownloadToStream(ms);
}
byte[] dataToWrite = Encoding.UTF8.GetBytes(line + "\r\n");
ms.Write(dataToWrite, 0, dataToWrite.Length);
ms.Position = 0;
outputBlob.UploadFromStream(ms);
}
}
示例5: UploadBlobInParallel
void UploadBlobInParallel(CloudBlockBlob blob, Stream stream)
{
blob.ServiceClient.ParallelOperationThreadCount = NumberOfIOThreads;
container.ServiceClient.RetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(BackOffInterval), MaxRetries);
blob.StreamWriteSizeInBytes = BlockSize;
blob.UploadFromStream(stream);
}
示例6: UploadBlob
private static void UploadBlob(CloudBlockBlob blob, RepositoryEntity obj)
{
using (var streamCompressed = new MemoryStream())
{
using (var gzip = new GZipStream(streamCompressed, CompressionMode.Compress))
{
var data = Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(obj));
gzip.Write(data, 0, data.Length);
gzip.Flush();
gzip.Close();
using (var streamOut = new MemoryStream(streamCompressed.ToArray()))
{
blob.UploadFromStream(streamOut);
}
}
}
}
示例7: UploadPicture
private static void UploadPicture(CloudBlockBlob blob, String path)
{
blob.Properties.ContentType = "image/jpeg";
using (var fileStream = File.OpenRead(path))
{
blob.UploadFromStream(fileStream);
}
}
示例8: UploadBlockBlob
public virtual void UploadBlockBlob(CloudBlockBlob blockBlob, Stream streamToUpload, AccessCondition accessCondition = null)
{
blockBlob.UploadFromStream(streamToUpload, accessCondition);
}
示例9: uploadButton_Click
protected void uploadButton_Click(object sender, EventArgs e)
{
if (photoUpload.HasFile)
{
string fullFileName = photoUpload.PostedFile.FileName;
string shortFileName = Path.GetFileName(fullFileName);
blockBlob = blobContainer.GetBlockBlobReference(shortFileName + DateTime.Now);
using (var fileStream = System.IO.File.OpenRead(fullFileName))
{
blockBlob.UploadFromStream(fileStream);
}
profileImage.ImageUrl = blockBlob.Uri.ToString();
}
}
示例10: UploadBlob
/// <summary>
/// Uploads the BLOB.
/// </summary>
/// <param name="blob">The BLOB.</param>
/// <param name="dataBytes">The data bytes.</param>
/// <param name="metaData">The meta data.</param>
/// <returns>System.String for ETag.</returns>
public static string UploadBlob(CloudBlockBlob blob, byte[] dataBytes, IDictionary<string, string> metaData)
{
try
{
if (metaData != null)
{
foreach (var key in metaData.Keys)
{
blob.Metadata.Merge(key, metaData[key]);
}
}
using (var msWrite = new MemoryStream(dataBytes))
{
msWrite.Position = 0;
blob.UploadFromStream(msWrite);
}
return blob.Properties.ETag;
}
catch (Exception ex)
{
throw ex.Handle("UploadBlob", new { blob = blob.Uri.ToString(), metaData = metaData });
}
}
示例11: UploadFromStream
private void UploadFromStream(CloudBlockBlob blob, Stream source)
{
try
{
blob.UploadFromStream(source);
}
catch (StorageException e)
{
throw new BlobException(string.Format(CultureInfo.InvariantCulture, "Could not UploadFromStream to blob named '{0}' in container. See inner exception for details.", blob.Name), e);
}
}
示例12: UploadBlobInParallel
private void UploadBlobInParallel(CloudBlockBlob blob, Stream stream)
{
try
{
blob.ServiceClient.ParallelOperationThreadCount = NumberOfIOThreads;
blob.UploadFromStream(stream);
}
catch (StorageException ex)
{
logger.Warn(ex.Message);
}
}
示例13: UseBlobSAS
static void UseBlobSAS(string sas)
{
//Try performing blob operations using the SAS provided.
//Return a reference to the blob using the SAS URI.
CloudBlockBlob blob = new CloudBlockBlob(new Uri(sas));
//Write operation: Write a new blob to the container.
try
{
string blobContent = "This blob was created with a shared access signature granting write permissions to the blob. ";
MemoryStream msWrite = new MemoryStream(Encoding.UTF8.GetBytes(blobContent));
msWrite.Position = 0;
using (msWrite)
{
blob.UploadFromStream(msWrite);
}
Console.WriteLine("Write operation succeeded for SAS " + sas);
Console.WriteLine();
}
catch (StorageException e)
{
Console.WriteLine("Write operation failed for SAS " + sas);
Console.WriteLine("Additional error information: " + e.Message);
Console.WriteLine();
}
//Read operation: Read the contents of the blob.
try
{
MemoryStream msRead = new MemoryStream();
using (msRead)
{
blob.DownloadToStream(msRead);
msRead.Position = 0;
using (StreamReader reader = new StreamReader(msRead, true))
{
string line;
while ((line = reader.ReadLine()) != null)
{
Console.WriteLine(line);
}
}
}
Console.WriteLine("Read operation succeeded for SAS " + sas);
Console.WriteLine();
}
catch (StorageException e)
{
Console.WriteLine("Read operation failed for SAS " + sas);
Console.WriteLine("Additional error information: " + e.Message);
Console.WriteLine();
}
//Delete operation: Delete the blob.
try
{
blob.Delete();
Console.WriteLine("Delete operation succeeded for SAS " + sas);
Console.WriteLine();
}
catch (StorageException e)
{
Console.WriteLine("Delete operation failed for SAS " + sas);
Console.WriteLine("Additional error information: " + e.Message);
Console.WriteLine();
}
}
示例14: TestEventsHelper
public void TestEventsHelper(CloudBlockBlob blob, int bufferSize, int expectedSending, int expectedResponseReceived, int expectedRequestComplete, int expectedRetry, bool testRetry)
{
byte[] buffer = GetRandomBuffer(bufferSize);
BlobRequestOptions blobOptions = new BlobRequestOptions();
blobOptions.SingleBlobUploadThresholdInBytes = EventFiringTests.SingleBlobUploadThresholdInBytes;
blobOptions.RetryPolicy = new OldStyleAlwaysRetry(new TimeSpan(1), maxRetries);
int sendingRequestFires = 0;
int responseReceivedFires = 0;
int requestCompleteFires = 0;
int retryFires = 0;
OperationContext.GlobalSendingRequest += (sender, args) => sendingRequestFires++;
OperationContext.GlobalResponseReceived += (sender, args) => responseReceivedFires++;
OperationContext.GlobalRequestCompleted += (sender, args) => requestCompleteFires++;
OperationContext.GlobalRetrying += (sender, args) => retryFires++;
if (testRetry)
{
using (MemoryStream wholeBlob = new MemoryStream())
{
try
{
blob.DownloadToStream(wholeBlob, null, blobOptions, null);
}
catch (StorageException e)
{
Assert.AreEqual(404, e.RequestInformation.HttpStatusCode);
}
}
}
else
{
using (MemoryStream wholeBlob = new MemoryStream(buffer))
{
blob.UploadFromStream(wholeBlob, null, blobOptions, null);
}
}
Assert.AreEqual(expectedSending, sendingRequestFires);
Assert.AreEqual(expectedResponseReceived, responseReceivedFires);
Assert.AreEqual(expectedRequestComplete, requestCompleteFires);
Assert.AreEqual(expectedRetry, retryFires);
}
示例15: UploadDocument
private static void UploadDocument(CloudBlockBlob blob, String path)
{
using (var fileStream = File.OpenRead(path))
{
blob.UploadFromStream(fileStream);
}
}