Example #1
0
        private async Task UploadFilesToAzure(string branch, IFormFileCollection files, string fileName)
        {
            foreach (var file in files)
            {
                byte[] bytes;
                using (var stream = file.OpenReadStream())
                {
                    bytes = new byte[stream.Length];
                    stream.Read(bytes, 0, (int)stream.Length);
                }

                var fileStream = (new MemoryStream(bytes));

                await AzureStorageUtil.UploadFromStream(fileStream, CBranch.ImagesContainer, fileName);

                var uri = AzureStorageUtil.GetUriFromBlob(CBranch.ImagesContainer, fileName);
                _branchImageBusiness.SaveBranchImages(new BranchImages()
                {
                    IdBranch      = new Guid(branch),
                    NameContainer = CBranch.ImagesContainer,
                    NameFile      = fileName,
                    UrlImage      = uri
                });
            }
        }
Example #2
0
        public string GetUrlAzureContainerbyStrem(MemoryStream File, string namefile, string extension)
        {
            DateTime localDate = DateTime.Now;

            MemoryStream stream = File;

            AzureStorageUtil.UploadFromStream(stream, "evidencias", namefile + extension).Wait();
            var uri = AzureStorageUtil.GetUriFromBlob("evidencias", namefile + extension);

            // loading bytes from a file is very easy in C#. The built in System.IO.File.ReadAll* methods take care of making sure every byte is read properly.

            return(uri);
        }
Example #3
0
        public int _SaveImagesAsync(int code)
        {
            // var result = await Task.Run(() => {
            //var equipos = _equipmentBusiness.GetEquipamentFotos(code);

            //foreach (var mod in equipos)
            //{
            var model        = code != 0 ? _equipmentBusiness.GetEquipment(code, ApplicationUserCurrent.AccountId) : null;
            var equipmenturi = _equipament_timeBusiness.GetEquipamentTimeImages(model.Id);

            foreach (var eu in equipmenturi)
            {
                var FotosEqu = _equipament_timeBusiness.GetEquipamentidtype(eu.Idequipament, Convert.ToInt32(eu.idstatus));
                if (FotosEqu.Count == 0)
                {
                    string       sql         = $@"select _uri Uri, _TOP_LEVEL_AURI, [Table], orden, valor from [dbo].[vw_FotosTopsy_P]  where _TOP_LEVEL_AURI = '{eu.aggregateuri}'";
                    var          images      = _equipamentImagesBusiness.GetImageEquipamentusri(sql);
                    MemoryStream imageStream = null;
                    foreach (var i in images)
                    {
                        imageStream = new MemoryStream(i.valor.ToArray());
                        AzureStorageUtil.UploadFromStream(imageStream, "implementacion", i.Uri + ".jpg").Wait();
                        var uri = AzureStorageUtil.GetUriFromBlob("implementacion", i.Uri + ".jpg");
                        var equipamentImages = new EquipamentImages()
                        {
                            IdEquipament  = model.Id,
                            NameContainer = i.Uri,
                            NameFile      = i.Uri + ".jpg",
                            UrlImage      = uri,
                            IdAccount     = Global.AccountId,
                            ORDER         = i.orden,
                            ContentType   = eu.idstatus.ToString()
                        };
                        _equipamentImagesBusiness.InsertImageEquipament(equipamentImages);
                    }
                }
            }
            //}
            return(1);

            /* });
             * return result;*/
        }