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


C# CloudBlockBlob.UploadFromByteArray方法代码示例

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


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

示例1: CreateBlob

		private void CreateBlob()
		{
			var account = CloudStorageAccount.Parse(Config.Get("DeepStorage.OutputConnectionString"));
			var blobClient = account.CreateCloudBlobClient();
			var container = blobClient.GetContainerReference(Config.Get("DeepStorage.OutputContainerName"));
			container.CreateIfNotExists();
			_blob = container.GetBlockBlobReference(_blobPath);
			if (!_blob.Exists())
			{
				_blob.UploadFromByteArray(new byte[] {},0, 0);
			}
		}
开发者ID:smartpcr,项目名称:bigdata2,代码行数:12,代码来源:BlobStorageEventStore.cs

示例2: PostEvent

        public async Task<IHttpActionResult> PostEvent(Event newEvent)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            if (newEvent.EventImage != null)
            {
                string storageString = ConfigurationManager.ConnectionStrings["StorageConnectionString"].ToString();
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageString);
                CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
                // Retrieve reference to a previously created container.
                CloudBlobContainer container = blobClient.GetContainerReference("profile-pictures");

                //Create the "images" container if it doesn't already exist.
                container.CreateIfNotExists();

                // Retrieve reference to a blob with this name
                blockBlob = container.GetBlockBlobReference("event_image_" + Guid.NewGuid());

                byte[] imageBytes = Convert.FromBase64String(newEvent.EventImage);

                // create or overwrite the blob named "image_" and the current date and time 
                blockBlob.UploadFromByteArray(imageBytes, 0, imageBytes.Length);

                newEvent.EventImage = getImageURL();
            }
            else
            {
                newEvent.EventImage = "https://posseup.blob.core.windows.net/profile-pictures/event_image_ab089d5f-0b47-4b56-a8c5-8b2e6ce71e70";
            }
            if (newEvent.EventVenue == null)
            {
                newEvent.EventVenue = new Place();
            }
            var validUsers = new List<InvitedUser>();
            if (newEvent.EventInvitedGuests != null)
            {
                foreach (InvitedUser user in newEvent.EventInvitedGuests)
                {
                    var legitUser = db.Users.Where(x => x.UserName.Equals(user.User.UserName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                    if (legitUser != null)
                    {
                        validUsers.Add(new InvitedUser() { User = legitUser, InvitedUserId = Guid.NewGuid()});
                        await inviteNotifications(newEvent, legitUser);
                    }
                }
                newEvent.EventInvitedGuests.Clear();
                newEvent.EventInvitedGuests = validUsers;
            }
            db.Events.Add(newEvent);
            db.SaveChanges();
            return CreatedAtRoute("DefaultApi", new { id = newEvent.EventID }, newEvent);
        }
开发者ID:DarkNormal,项目名称:PosseNetAPIApp,代码行数:54,代码来源:EventsController.cs

示例3: Register

        public async Task<HttpResponseMessage> Register(RegisterBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
            }
            if (model.ProfileImageURL != null)
            {
                string storageString = ConfigurationManager.ConnectionStrings["StorageConnectionString"].ToString();
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageString);
                CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
                // Retrieve reference to a previously created container.
                CloudBlobContainer container = blobClient.GetContainerReference("profile-pictures");

                //Create the "images" container if it doesn't already exist.
                container.CreateIfNotExists();

                // Retrieve reference to a blob with this name
                blockBlob = container.GetBlockBlobReference("profile_image_" + Guid.NewGuid());

                byte[] imageBytes = Convert.FromBase64String(model.ProfileImageURL);

                // create or overwrite the blob named "image_" and the current date and time 
                blockBlob.UploadFromByteArray(imageBytes, 0, imageBytes.Length);

                model.ProfileImageURL = getImageURL();
            }
            else
            {
                model.ProfileImageURL = "https://posseup.blob.core.windows.net/profile-pictures/05-512.png";
            }

            var user = new ApplicationUser() { UserName = model.UserName, Email = model.Email, ProfileImageURL = model.ProfileImageURL };

            IdentityResult result = await UserManager.CreateAsync(user, model.Password);

            if (!result.Succeeded)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest, result);
            }
            var myMessage = new SendGridMessage();
            myMessage.From = new MailAddress("[email protected]");
            myMessage.AddTo(string.Format(@"{0} <{1}>", user.UserName, user.Email));
            myMessage.Subject = "Welcome to Posse Up!";
            myMessage.Html = "<p>Hello World!</p>";
            myMessage.Text = "Hello World plain text!";
            await SendEmail(myMessage);
            // Send the email.
           
            return Request.CreateResponse(HttpStatusCode.OK, model);
        }
开发者ID:DarkNormal,项目名称:PosseNetAPIApp,代码行数:51,代码来源:AccountController.cs

示例4: UploadImage

        private string UploadImage(string encodedImage)
        {
            // Retrieve storage account from connection string.
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                "");
            //Sensitive information was replaced with ** from the above string for protection

            // Create the blob client.
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

            // Retrieve reference to a previously created container.
            CloudBlobContainer container = blobClient.GetContainerReference("images");

            //Create the "images" container if it doesn't already exist.
            container.CreateIfNotExists();

            // Retrieve reference to a blob with this name
            //Images will be saved in the format "image_[Guid][Date]"
            blockBlob = container.GetBlockBlobReference("image_" + Guid.NewGuid() + System.DateTime.Now);

            byte[] imageBytes = Convert.FromBase64String(encodedImage);

            // create or overwrite the blob named "image_" and the current date and time 
            blockBlob.UploadFromByteArray(imageBytes, 0, imageBytes.Length);

            //Set the expiry time and permissions for the blob.
            //Start time is not specified meaning that this SAS is activated immediately
           
            SharedAccessBlobPolicy sasConstraints = new SharedAccessBlobPolicy();
            //Access is Valid for a week
            sasConstraints.SharedAccessExpiryTime = DateTime.UtcNow.AddDays(7);
            sasConstraints.Permissions = SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.Write;

            //Generate the shared access signature on the blob, setting the constraints directly on the signature.
            string sasBlobToken = blockBlob.GetSharedAccessSignature(sasConstraints);

            //Return the URI string for the container, including the SAS token.
            return blockBlob.Uri + sasBlobToken;
        }
开发者ID:robbiekenny,项目名称:HomeSecurity-Backend-Part2,代码行数:39,代码来源:SendEmailController.cs

示例5: blobUpload

        public bool blobUpload(byte[] content, string filename, string folder, string container)
        {
            try
            {
                blob = blobClient.GetContainerReference(container);
                blob.CreateIfNotExists();

                blockBlob = blob.GetBlockBlobReference(folder + @"/" + filename);

                //upload to tmp container
                blockBlob.UploadFromByteArray(content, 0, content.Count<byte>(), null, null, null);

                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
开发者ID:dkouznet3,项目名称:ScaleDemo,代码行数:19,代码来源:Storage.cs


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