コード例 #1
0
        private async Task <string> SaveImageToCloudAsync(IFormFile image)
        {
            var imageName = $"{Guid.NewGuid()}_{image.FileName}";
            StorageAccountHelper storageHelper = new StorageAccountHelper();

            storageHelper.StorageConnectionString = configuration.GetConnectionString("StorageConnection");
            var fileUrl = await storageHelper.UploadFileToBlobAsync("eshopimages", imageName, image.OpenReadStream());

            return(fileUrl);
        }
コード例 #2
0
        private async Task <string> SaveImageToCloudAsync(IFormFile image)
        {
            var imageName = $"{Guid.NewGuid()}_{image.FileName}";
            var tempFile  = Path.GetTempFileName();

            using (FileStream fs = new FileStream(tempFile, FileMode.Create))
            {
                await image.CopyToAsync(fs);
            }
            var imageFile = Path.Combine(Path.GetDirectoryName(tempFile), imageName);

            System.IO.File.Move(tempFile, imageFile);
            StorageAccountHelper accountHelper = new StorageAccountHelper();

            accountHelper.StorageConnectonString = configuration.GetConnectionString("StorageConnection");
            var fileUri = await accountHelper.UploadFileToBlobAsync(imageFile, "eshopimages");

            return(fileUri);
        }
コード例 #3
0
        private async Task <string> SaveImageToCloudAsync(IFormFile image)
        {
            var imagename = $"{Guid.NewGuid()}_{image.FileName}"; // image name must be unique
            var tempFile  = Path.GetTempFileName();

            using (FileStream fs = new FileStream(tempFile, FileMode.Create))
            {
                await image.CopyToAsync(fs);
            }
            var imageFile = Path.Combine(Path.GetDirectoryName(tempFile), imagename);

            System.IO.File.Move(tempFile, imageFile); // renaming of temp file
            StorageAccountHelper storageHelper = new StorageAccountHelper();

            storageHelper.StorageConnectionString = _configuration.GetConnectionString("StorageConnection");
            var fileUrl = await storageHelper.UploadFileToBlobAsync(imageFile, "eshopimages"); // uploading to cloud

            System.IO.File.Delete(imageFile);                                                  // delete local storage file after upload
            return(fileUrl);
        }
コード例 #4
0
        private async Task <string> SaveImageToCloudAsync(IFormFile image)
        {
            var imageName = $"{Guid.NewGuid()}_{image.FileName}";
            var tempFile  = Path.GetTempFileName();

            using (FileStream fs = new FileStream(tempFile, FileMode.Create))  // uploading the file to the tempfile
            {
                await image.CopyToAsync(fs);
            }

            var imageFile = Path.Combine(Path.GetDirectoryName(tempFile), imageName); // rename the tempfile name to real file name

            System.IO.File.Move(tempFile, imageFile);                                 // Move() function is use to rename file
            StorageAccountHelper storageHelper = new StorageAccountHelper();

            storageHelper.StorageConnectionString = config.GetConnectionString("StorageConnection");
            var fileUri = await storageHelper.UploadFileToBlobAsync(imageFile, "eshopimages");

            System.IO.File.Delete(imageFile); // to delete the tempFolder after image get uploaded on cloud
            return(fileUri);
        }
コード例 #5
0
        private async Task <string> SaveImageToCloudAsync(IFormFile image)
        {
            var imageName = $"{Guid.NewGuid()}_{image.FileName}";
            var tempFile  = Path.GetTempFileName();

            using (FileStream fs = new FileStream(tempFile, FileMode.Create))
            {
                await image.CopyToAsync(fs);
            }

            var imageFile = Path.Combine(Path.GetDirectoryName(tempFile), imageName);

            System.IO.File.Move(tempFile, imageFile);
            StorageAccountHelper storageHelper = new StorageAccountHelper();

            storageHelper.StorageConnectionString = configuration.GetConnectionString("StorageConnection");
            var fileUri = await storageHelper.UploadFileToBlobAsync(imageFile, "eshopimages");

            System.IO.File.Delete(imageFile);
            //+ "?sv=2019-02-02&ss=b&srt=co&sp=rl&se=2019-11-06T14:58:12Z&st=2019-11-06T06:58:12Z&spr=https&sig=5L1b%2Fn3Rfr5V7X5m4OwiLxnQ9OF6SDjuiFf9ax3rWvY%3D";
            return(fileUri);
        }
コード例 #6
0
        private async Task <string> SaveImageToCloudAsync(IFormFile image)
        {
            var imageName = $"{Guid.NewGuid()}_{Request.Form.Files[0].FileName}";
            var tempFile  = Path.GetTempFileName();

            using (FileStream fs = new FileStream(tempFile, FileMode.Create))
            {
                await image.CopyToAsync(fs);
            }

            var imageFile = Path.Combine(Path.GetDirectoryName(tempFile), imageName);

            System.IO.File.Move(tempFile, imageFile);
            StorageAccountHelper storageHelper = new StorageAccountHelper();

            storageHelper.StorageConnectionString = config.GetConnectionString("StorageConnection");
            var fileUri = await storageHelper.UploadFileToBlobAsync(imageFile, "eHotelsgalleryimages");

            System.IO.File.Delete(imageFile);

            //fileUri = fileUri + "?sv=2019-02-02&ss=bfq&srt=sco&sp=rwdlacup&se=2019-11-15T15:22:16Z&st=2019-11-06T07:22:16Z&spr=https&sig=Bshl%2Bplh44Wu3w4e8XIGemZgLhamR%2FrFXdDvIqJdkbg%3D";
            return(fileUri);
        }