當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。