本文整理匯總了C#中Microsoft.WindowsAzure.Storage.File.CloudFile.UploadFromFileAsync方法的典型用法代碼示例。如果您正苦於以下問題:C# CloudFile.UploadFromFileAsync方法的具體用法?C# CloudFile.UploadFromFileAsync怎麽用?C# CloudFile.UploadFromFileAsync使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Microsoft.WindowsAzure.Storage.File.CloudFile
的用法示例。
在下文中一共展示了CloudFile.UploadFromFileAsync方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: DoUploadDownloadFileAsync
private async Task DoUploadDownloadFileAsync(CloudFile file, int fileSize)
{
StorageFolder tempFolder = ApplicationData.Current.TemporaryFolder;
StorageFile inputFile = await tempFolder.CreateFileAsync("input.file", CreationCollisionOption.GenerateUniqueName);
StorageFile outputFile = await tempFolder.CreateFileAsync("output.file", CreationCollisionOption.GenerateUniqueName);
try
{
byte[] buffer = GetRandomBuffer(fileSize);
using (Stream localFile = await inputFile.OpenStreamForWriteAsync())
{
await localFile.WriteAsync(buffer, 0, buffer.Length);
}
await file.UploadFromFileAsync(inputFile);
OperationContext context = new OperationContext();
await file.UploadFromFileAsync(inputFile, null, null, context);
Assert.IsNotNull(context.LastResult.ServiceRequestID);
context = new OperationContext();
await file.DownloadToFileAsync(outputFile, null, null, context);
Assert.IsNotNull(context.LastResult.ServiceRequestID);
using (Stream inputFileStream = await inputFile.OpenStreamForReadAsync(),
outputFileStream = await outputFile.OpenStreamForReadAsync())
{
TestHelper.AssertStreamsAreEqual(inputFileStream, outputFileStream);
}
}
finally
{
inputFile.DeleteAsync().AsTask().Wait();
outputFile.DeleteAsync().AsTask().Wait();
}
}
示例2: DoUploadDownloadFileAsync
private async Task DoUploadDownloadFileAsync(CloudFile file, int fileSize)
{
string inputFileName = Path.GetTempFileName();
string outputFileName = Path.GetTempFileName();
try
{
byte[] buffer = GetRandomBuffer(fileSize);
using (FileStream fileStream = new FileStream(inputFileName, FileMode.Create, FileAccess.Write))
{
await fileStream.WriteAsync(buffer, 0, buffer.Length);
}
await file.UploadFromFileAsync(inputFileName, FileMode.Open);
OperationContext context = new OperationContext();
await file.UploadFromFileAsync(inputFileName, FileMode.Open, null, null, context);
Assert.IsNotNull(context.LastResult.ServiceRequestID);
await TestHelper.ExpectedExceptionAsync<IOException>(
async () => await file.DownloadToFileAsync(outputFileName, FileMode.CreateNew),
"CreateNew on an existing file should fail");
context = new OperationContext();
await file.DownloadToFileAsync(outputFileName, FileMode.Create, null, null, context);
Assert.IsNotNull(context.LastResult.ServiceRequestID);
using (
FileStream inputFileStream = new FileStream(inputFileName, FileMode.Open, FileAccess.Read),
outputFileStream = new FileStream(outputFileName, FileMode.Open, FileAccess.Read))
{
await TestHelper.AssertStreamsAreEqualAsync(inputFileStream, outputFileStream);
}
await file.DownloadToFileAsync(outputFileName, FileMode.Append);
using (
FileStream inputFileStream = new FileStream(inputFileName, FileMode.Open, FileAccess.Read),
outputFileStream = new FileStream(outputFileName, FileMode.Open, FileAccess.Read))
{
Assert.AreEqual(2 * fileSize, outputFileStream.Length);
for (int i = 0; i < fileSize; i++)
{
Assert.AreEqual(inputFileStream.ReadByte(), outputFileStream.ReadByte());
}
inputFileStream.Seek(0, SeekOrigin.Begin);
for (int i = 0; i < fileSize; i++)
{
Assert.AreEqual(inputFileStream.ReadByte(), outputFileStream.ReadByte());
}
}
}
finally
{
File.Delete(inputFileName);
File.Delete(outputFileName);
}
}
示例3: DoUploadDownloadFileAsync
private async Task DoUploadDownloadFileAsync(CloudFile file, int fileSize)
{
#if ASPNET_K
string inputFileName = Path.GetTempFileName();
string outputFileName = Path.GetTempFileName();
if (System.IO.File.Exists(outputFileName))
{
System.IO.File.Delete(outputFileName);
}
try
{
byte[] buffer = GetRandomBuffer(fileSize);
using (FileStream localFile = new FileStream(inputFileName, FileMode.Create, FileAccess.Write))
{
await localFile.WriteAsync(buffer, 0, buffer.Length);
}
await file.UploadFromFileAsync(inputFileName);
OperationContext context = new OperationContext();
await file.UploadFromFileAsync(inputFileName, null, null, context);
Assert.IsNotNull(context.LastResult.ServiceRequestID);
context = new OperationContext();
await file.DownloadToFileAsync(outputFileName, FileMode.CreateNew, null, null, context);
Assert.IsNotNull(context.LastResult.ServiceRequestID);
using (FileStream inputFile = new FileStream(inputFileName, FileMode.Open, FileAccess.Read),
outputFile = new FileStream(outputFileName, FileMode.Open, FileAccess.Read))
{
TestHelper.AssertStreamsAreEqual(inputFile, outputFile);
}
}
finally
{
System.IO.File.Delete(inputFileName);
System.IO.File.Delete(outputFileName);
}
#else
StorageFolder tempFolder = ApplicationData.Current.TemporaryFolder;
StorageFile inputFile = await tempFolder.CreateFileAsync("input.file", CreationCollisionOption.GenerateUniqueName);
StorageFile outputFile = await tempFolder.CreateFileAsync("output.file", CreationCollisionOption.GenerateUniqueName);
try
{
byte[] buffer = GetRandomBuffer(fileSize);
using (Stream localFile = await inputFile.OpenStreamForWriteAsync())
{
await localFile.WriteAsync(buffer, 0, buffer.Length);
}
await file.UploadFromFileAsync(inputFile);
OperationContext context = new OperationContext();
await file.UploadFromFileAsync(inputFile, null, null, context);
Assert.IsNotNull(context.LastResult.ServiceRequestID);
context = new OperationContext();
await file.DownloadToFileAsync(outputFile, null, null, context);
Assert.IsNotNull(context.LastResult.ServiceRequestID);
using (Stream inputFileStream = await inputFile.OpenStreamForReadAsync(),
outputFileStream = await outputFile.OpenStreamForReadAsync())
{
TestHelper.AssertStreamsAreEqual(inputFileStream, outputFileStream);
}
}
finally
{
inputFile.DeleteAsync().AsTask().Wait();
outputFile.DeleteAsync().AsTask().Wait();
}
#endif
}