当前位置: 首页>>代码示例>>C#>>正文


C# CloudBlockBlob.UploadFromFile方法代码示例

本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.UploadFromFile方法的典型用法代码示例。如果您正苦于以下问题:C# CloudBlockBlob.UploadFromFile方法的具体用法?C# CloudBlockBlob.UploadFromFile怎么用?C# CloudBlockBlob.UploadFromFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob的用法示例。


在下文中一共展示了CloudBlockBlob.UploadFromFile方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: uploadfromFilesystem

 public void uploadfromFilesystem(CloudBlockBlob blob, string localFilePath, string eventType)
 {
     if (eventType.Equals("create") || eventType.Equals("signUpStart"))
     {
         Program.ClientForm.addtoConsole("Upload started[create || signUpStart]:" + localFilePath);
         blob.UploadFromFile(localFilePath, FileMode.Open);
         Program.ClientForm.addtoConsole("Uploaded");
         Program.ClientForm.ballon("Uploaded:"+ localFilePath);
     }
     else
     {
         try
         {
             Program.ClientForm.addtoConsole("Upload started[change,etc]:" + localFilePath);
             string leaseId = Guid.NewGuid().ToString();
             blob.AcquireLease(TimeSpan.FromMilliseconds(16000), leaseId);
             blob.UploadFromFile(localFilePath, FileMode.Open, AccessCondition.GenerateLeaseCondition(leaseId));
             blob.ReleaseLease(AccessCondition.GenerateLeaseCondition(leaseId));
             Program.ClientForm.addtoConsole("Uploaded");
             Program.ClientForm.ballon("Uploaded:" + localFilePath);
         }
         catch (Exception ex)
         {
             Program.ClientForm.addtoConsole("Upload: second attempt");
             Thread.Sleep(5000);
             string leaseId = Guid.NewGuid().ToString();
             blob.AcquireLease(TimeSpan.FromMilliseconds(16000), leaseId);
             blob.UploadFromFile(localFilePath, FileMode.Open, AccessCondition.GenerateLeaseCondition(leaseId));
             blob.ReleaseLease(AccessCondition.GenerateLeaseCondition(leaseId));
             Program.ClientForm.addtoConsole("Uploaded");
             Program.ClientForm.ballon("Uploaded:" + localFilePath);
         }
     }
 }
开发者ID:hangmiao,项目名称:DBLike,代码行数:34,代码来源:LocalFileSys.cs

示例2: ProcessFiles

        /// <summary>
        /// Process sample Files for generating test data
        /// </summary>
        /// <param name="path"></param>
        /// <param name="outputStorageAccount"></param>
        /// <param name="folderPath"></param>
        /// <param name="outputTableName"></param>
        /// <param name="logger"></param>
        public static void ProcessFiles(string path, CloudStorageAccount outputStorageAccount, string folderPath, string outputTableName, IActivityLogger logger)
        {
            string[] files = Directory.GetFiles(path);

            foreach (var file in files)
            {
                if (file.Contains(@"artist_data.txt") && outputTableName.ToLower().Contains(@"catalog"))
                {
                    Uri outputBlobUri = new Uri(outputStorageAccount.BlobEndpoint, folderPath + "artist_data.txt");
                    CloudBlockBlob outputBlob = new CloudBlockBlob(outputBlobUri, outputStorageAccount.Credentials);
                    if (outputBlob.Exists())
                    {
                        outputBlob.Delete();
                    }
                    outputBlob.UploadFromFile(path + "/artist_data.txt", FileMode.Open);
                }
                if (file.Contains(@"customers.txt") && outputTableName.ToLower().Contains(@"customers"))
                {
                    Uri outputBlobUri = new Uri(outputStorageAccount.BlobEndpoint, folderPath + "customers.txt");
                    CloudBlockBlob outputBlob = new CloudBlockBlob(outputBlobUri, outputStorageAccount.Credentials);
                    if (outputBlob.Exists())
                    {
                        outputBlob.Delete();
                    }
                    outputBlob.UploadFromFile(path + "/customers.txt", FileMode.Open);
                }
                else if (file.Contains(@"artist_customer_data.txt") && outputTableName.ToLower().Contains(@"rawproducts"))
                {
                    Uri outputBlobUri = new Uri(outputStorageAccount.BlobEndpoint, folderPath + "artist_customer_data.txt");
                    CloudBlockBlob outputBlob = new CloudBlockBlob(outputBlobUri, outputStorageAccount.Credentials);
                    List<string> lines = File.ReadAllLines(path + "/artist_customer_data.txt").ToList();
                    int index = 0;

                    if (outputBlob.Exists() && index == 0)
                    {
                        outputBlob.Delete();
                    }

                    //add new column value for each row.
                    lines.Skip(0).ToList().ForEach(line =>
                    {
                        if (index >= 0 & index <= 1000)
                        {
                            lines[index] += "," + DateTime.UtcNow.AddMonths(-1).ToString("yyyy-MM-dd");
                            UploadBlobStream(outputBlob, lines[index]);
                            index++;
                        }
                        else if (index >= 1001 & index <= 2000)
                        {
                            lines[index] += "," + DateTime.UtcNow.AddMonths(-2).ToString("yyyy-MM-dd");
                            UploadBlobStream(outputBlob, lines[index]);
                            index++;
                        }
                        else if (index >= 2001 & index <= 3000)
                        {
                            lines[index] += "," + DateTime.UtcNow.AddMonths(-3).ToString("yyyy-MM-dd");
                            UploadBlobStream(outputBlob, lines[index]);
                            index++;
                        }
                        else if (index >= 3001 & index <= 4000)
                        {
                            lines[index] += "," + DateTime.UtcNow.AddMonths(-4).ToString("yyyy-MM-dd");
                            UploadBlobStream(outputBlob, lines[index]);
                            index++;
                        }
                        else if (index >= 4001 & index <= 5000)
                        {
                            lines[index] += "," + DateTime.UtcNow.AddMonths(-5).ToString("yyyy-MM-dd");
                            UploadBlobStream(outputBlob, lines[index]);
                            index++;
                        }
                        else if (index >= 5001 & index <= 6000)
                        {
                            lines[index] += "," + DateTime.UtcNow.AddMonths(-6).ToString("yyyy-MM-dd");
                            UploadBlobStream(outputBlob, lines[index]);
                            index++;
                        }
                        else if (index >= 6001 & index <= 7000)
                        {
                            lines[index] += "," + DateTime.UtcNow.AddMonths(-7).ToString("yyyy-MM-dd");
                            UploadBlobStream(outputBlob, lines[index]);
                            index++;
                        }
                        else if (index >= 7001 & index <= 8000)
                        {
                            lines[index] += "," + DateTime.UtcNow.AddMonths(-8).ToString("yyyy-MM-dd");
                            UploadBlobStream(outputBlob, lines[index]);
                            index++;
                        }
                        else if (index >= 8001 & index <= 9000)
                        {
                            lines[index] += "," + DateTime.UtcNow.AddMonths(-9).ToString("yyyy-MM-dd");
//.........这里部分代码省略.........
开发者ID:CarlRabeler,项目名称:WingTipTickets,代码行数:101,代码来源:DataGenerator.cs

示例3: UploadFileToApplicationPackage

        private void UploadFileToApplicationPackage(
            string resourceGroupName,
            string accountName,
            string applicationId,
            string version,
            string filePath,
            string storageUrl,
            bool appPackageAlreadyExists)
        {
            try
            {
                CloudBlockBlob blob = new CloudBlockBlob(new Uri(storageUrl));
                blob.UploadFromFile(filePath, FileMode.Open);
            }
            catch (Exception exception)
            {
                // If the application package has already been created we don't want to delete the application package mysteriously.
                if (appPackageAlreadyExists)
                {
                    // If we are creating a new application package and the upload fails we should delete the application package.
                    try
                    {
                        DeleteApplicationPackage(resourceGroupName, accountName, applicationId, version);
                    }
                    catch
                    {
                        // Need to throw if we fail to delete the application while attempting to clean it up.
                        var deleteMessage = string.Format(Resources.FailedToUploadAndDelete, filePath, exception.Message);
                        throw new NewApplicationPackageException(deleteMessage, exception);
                    }
                }

                // Need to throw if we fail to upload the file's content.
                var uploadMessage = string.Format(Resources.FailedToUpload, filePath, exception.Message);
                throw new NewApplicationPackageException(uploadMessage, exception);
            }
        }
开发者ID:Azure,项目名称:azure-powershell,代码行数:37,代码来源:BatchClient.ApplicationPackages.cs

示例4: UploadBlob

        private static void UploadBlob(string packageFileName, string packageUrl, string storageAccountName, string storageAccountKey)
        {
            OurTrace.TraceInfo(string.Format("Uploading blob from {0} to {1}", packageFileName, packageUrl));

            var packageUri = new Uri(packageUrl);
            var credentials = new StorageCredentials(storageAccountName, storageAccountKey);
            var blobRef = new CloudBlockBlob(packageUri, credentials);

            blobRef.ServiceClient.DefaultRequestOptions.ServerTimeout = TimeSpan.FromMinutes(15);
            blobRef.ServiceClient.DefaultRequestOptions.MaximumExecutionTime = blobRef.ServiceClient.DefaultRequestOptions.ServerTimeout;
            blobRef.Container.CreateIfNotExists();

            blobRef.UploadFromFile(packageFileName, FileMode.Open);
        }
开发者ID:mg-alfa-dev,项目名称:DeployToAzure,代码行数:14,代码来源:Program.cs

示例5: TaskMain

        public static void TaskMain(string[] args)
        {
            if (args == null || args.Length != 4)
            {
                throw new Exception("Usage: ImageBlur.exe --Task <blobpath> <storageAccountName> <storageAccountKey>");
            }

            string blobName = args[1];
            string storageAccountName = args[2];
            string storageAccountKey = args[3];
            string workingDirectory = Environment.GetEnvironmentVariable("AZ_BATCH_TASK_WORKING_DIR");
            int numberToBlur = 3;

            Console.WriteLine();
            Console.WriteLine("    blobName: <{0}>", blobName);
            Console.WriteLine("    storageAccountName: <{0}>", storageAccountName);
            Console.WriteLine("    number to blur: <{0}>", numberToBlur);
            Console.WriteLine();

            // get source image from cloud blob
            var storageCred = new StorageCredentials(storageAccountName, storageAccountKey);
            CloudBlockBlob blob = new CloudBlockBlob(new Uri(blobName), storageCred);

            using (MemoryStream inStream = new MemoryStream())
            {
                blob.DownloadToStream(inStream);
                Image img = Image.FromStream(inStream);
                int imgWidth = img.Width;
                int imgHeight = img.Height;
                Size size = new Size(imgWidth, imgHeight);
                ISupportedImageFormat format = new JpegFormat { Quality = 70 };

                // Print image properties to stdout
                Console.WriteLine("    Image Properties:");
                Console.WriteLine("        Format: {0}", FormatUtilities.GetFormat(inStream));
                Console.WriteLine("        Size: {0}", size.ToString());
                Console.WriteLine();

                for (var i = 0; i < numberToBlur; i++)
                {
                    using (ImageFactory imageFactory = new ImageFactory(preserveExifData: true))
                    {
                        int blurIndex = (i * 5) + 10;
                        imageFactory.Load(inStream);
                        imageFactory.Resize(size)
                                    .Format(format)
                                    .GaussianBlur(blurIndex)
                                    .Save(workingDirectory + "/resultimage" + i + ".Jpeg");
                                    //.Save(@"C:/Users/jiata/Desktop/imageblur/results/resultimage" + i + ".Jpeg");
                    }
                }
            }

            // TODO - not working
            for (var i = 0; i < numberToBlur; i++)
            {
                blob.UploadFromFile(workingDirectory + "/resultimage" + i + ".Jpeg", FileMode.Open);
            }

            Environment.Exit(1);
        }
开发者ID:jiata,项目名称:BatchImageBlur,代码行数:61,代码来源:ImageBlur.cs

示例6: CreateApplicationPackage

        /// <summary>
        /// Uploads an application package to Storage
        /// </summary>
        public static AddApplicationPackageResult CreateApplicationPackage(BatchController controller, BatchAccountContext context, string applicationId, string version, string filePath)
        {
            AddApplicationPackageResult applicationPackage = null;

            if (HttpMockServer.Mode == HttpRecorderMode.Record)
            {
                applicationPackage = controller.BatchManagementClient.Application.AddApplicationPackage(
                    context.ResourceGroupName,
                    context.AccountName,
                    applicationId,
                    version);

                CloudBlockBlob blob = new CloudBlockBlob(new Uri(applicationPackage.StorageUrl));
                blob.UploadFromFile(filePath, FileMode.Open);
            }

            return applicationPackage;
        }
开发者ID:brnleehng,项目名称:azure-powershell,代码行数:21,代码来源:ScenarioTestHelpers.cs


注:本文中的Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.UploadFromFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。