Exemple #1
0
        public void DeleteData(string containerName, string filename)
        {
            // get target clients
            BlobServiceClient _targetClient;

            if (_clients.ContainsKey(TARGET_CLIENT_NAME))
            {
                _targetClient = _clients[TARGET_CLIENT_NAME];
            }
            else
            {
                _clients.Add(TARGET_CLIENT_NAME, new BlobServiceClient(Environment.GetEnvironmentVariable("TargetClientConn")));
                _targetClient = _clients[TARGET_CLIENT_NAME];
            }

            try
            {
                BlobContainerClient blobContainerTarget = _targetClient.GetBlobContainerClient(containerName);
                BlobClient          blob = blobContainerTarget.GetBlobClient(filename);
                blob.DeleteIfExists();
            }
            catch (Exception ex)
            {
                throw new Exception($"Unable to delete data '{filename}'", ex);
            }
        }
        public void DeleteFile(string container, string fileName)
        {
            BlobContainerClient containerClient = new BlobContainerClient(_connectionString, container);
            BlobClient          blobClient      = containerClient.GetBlobClient(fileName);

            blobClient.DeleteIfExists();
        }
        public async Task <IActionResult> UploadImage(IFormFile pictures)
        {
            string uri = "";

            try
            {
                Request.Headers.TryGetValue("Authorization", out var token);
                string email                  = _accountManager.GetEmailByToken(token);
                var    abb                    = pictures;
                var    pictureName            = $"{email}{Path.GetExtension(pictures.FileName)}";
                string connectionString       = "DefaultEndpointsProtocol=https;AccountName=cs1100320008fffce60;AccountKey=dJWONx/tF0HqzafLAm90h7zgXEsUXcPBDCL5gfBbJ71RgHBzpl3pHZ86yPxg12MP4+9XBJkq2d4NYZJuuf0kOg==;EndpointSuffix=core.windows.net";
                string containerName          = "ppsystem-blob";
                BlobContainerClient container = new BlobContainerClient(connectionString, containerName);
                // Get a reference to a blob
                BlobClient blob = container.GetBlobClient(pictureName);
                blob.DeleteIfExists();
                // Open the file and upload its data
                using (Stream file = pictures.OpenReadStream())
                {
                    blob.Upload(file);
                }
                uri = blob.Uri.AbsoluteUri;
                User account = _context.User.FirstOrDefault(a => a.Email == email);
                account.Avatar = uri;
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                return(Conflict("Something went wrong!!! " + ex.Message));
            }
            return(Ok("Success"));
        }
Exemple #4
0
        public static async Task Run([BlobTrigger("axeptiablob/{name}", Connection = "AzureWebJobsStorage")] Stream myBlob, string name, ILogger log)
        {
            log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");

            string blobConnectionString = "AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;DefaultEndpointsProtocol=http;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;";
            string blobContainerName    = "axeptiablob";

            var Reader       = new StreamReader(myBlob);
            var fileAsString = Reader.ReadToEnd();

            Reader.Close();

            BlobClient blobClient = new BlobClient(blobConnectionString, blobContainerName, name);
            Publisher  Publisher  = new Publisher();
            Converter  Converter  = new Converter();

            List <LineItem> personnel = Converter.StringToList(fileAsString);

            string jsonFileName = Converter.ListToJsonFile(personnel);

            await Publisher.SetupAndSendMessage(jsonFileName);

            blobClient.DeleteIfExists();

            log.LogInformation($"End of program");
        }
        public void Delete(long id)
        {
            var        connectionString  = _configuration.GetSection("Storage:ConnectionString").Value;
            var        blobContainerName = _configuration.GetSection("Storage:ContainerName").Value;
            string     path       = $"Recipes/{id}/";
            BlobClient blobClient = new BlobClient(connectionString, blobContainerName, path);

            blobClient.DeleteIfExists();
        }
Exemple #6
0
        /// <summary>
        /// Deletes the blob
        /// Blob will only be deleted if it exists
        /// </summary>
        /// <param name="blobName">The name of the blob to delete</param>
        /// <returns></returns>
        public async Task Delete(string blobName)
        {
            var uri = await auth.GetSasTokenAsync(blobName);

            //build the blob:
            var blob = new BlobClient(uri);

            blob.DeleteIfExists();
        }
        public void DeleteFile(string uri)
        {
            var strSplit = uri.Split('/');

            var cloudfilename = strSplit[strSplit.Length - 2] + "/" + strSplit[strSplit.Length - 1];

            BlobContainerClient containerClient = new BlobContainerClient(_connectionString, strSplit[strSplit.Length - 3]);
            BlobClient          blobClient      = containerClient.GetBlobClient(cloudfilename);

            blobClient.DeleteIfExists();
        }
        public static bool AddPicture(string name, Stream picture)
        {
            BlobClient blob = container.GetBlobClient(name);

            blob.DeleteIfExists(DeleteSnapshotsOption.IncludeSnapshots);
            try
            {
                blob.Upload(picture);
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }
        public async Task SaveSyncStateAsync(List <SyncedTask> syncedTasks)
        {
            BlobContainerClient blobContainerClient = new BlobContainerClient(storageConnectionString, containerName);
            await blobContainerClient.CreateIfNotExistsAsync();

            string outlookTasksJson = JsonSerializer.Serialize(syncedTasks);

            byte[]       outlookTasksByteArray = Encoding.UTF8.GetBytes(outlookTasksJson);
            MemoryStream outlookTasksStream    = new MemoryStream(outlookTasksByteArray);

            BlobClient lastSyncStateBlobClient = blobContainerClient.GetBlobClient(blobName);

            lastSyncStateBlobClient.DeleteIfExists();
            lastSyncStateBlobClient.Upload(outlookTasksStream);
        }
        public async Task UpdateRepos(List <Campaign> data)
        {
            var requestBody = JsonConvert.SerializeObject(data, Formatting.Indented);

            string              storageConnectionString = Environment.GetEnvironmentVariable("AzureWebJobsStorage");
            BlobServiceClient   blobServiceClient       = new BlobServiceClient(storageConnectionString);
            BlobContainerClient containerClient         = blobServiceClient.GetBlobContainerClient("repos");
            BlobClient          blobClient = containerClient.GetBlobClient("Repos.json");

            blobClient.DeleteIfExists();

            using (var stream = new MemoryStream(Encoding.Default.GetBytes(requestBody), false))
            {
                await blobClient.UploadAsync(stream);
            }
        }
        private void CreateSampleQueryBlob(IConfigurationRoot config)
        {
            var blobClient = new BlobClient(config["Azure:ConnectionString"], config["Azure:ContainerName"], "Queries/SampleQuery.json");
            var json       = JsonSerializer.Serialize(SampleQuery());
            var bytes      = Encoding.UTF8.GetBytes(json);

            using (var ms = new MemoryStream(bytes))
            {
                blobClient.DeleteIfExists();
                blobClient.Upload(ms, new BlobUploadOptions()
                {
                    HttpHeaders = new BlobHttpHeaders()
                    {
                        ContentType = "application/json"
                    }
                });
            }
        }
Exemple #12
0
        private static void FileSystemWatcher_Created(object sender, FileSystemEventArgs e)
        {
            // Get Container reference
            BlobContainerClient container = BlobServiceClient.GetBlobContainerClient("uploads");

            container.CreateIfNotExists();

            // Get reference to the blob
            BlobClient blob = container.GetBlobClient(e.Name);

            // Delete the blob if it already exists
            blob.DeleteIfExists();

            // Upload file to blob
            Console.WriteLine("Uploading to BlobStorage: {0}", e.FullPath);
            blob.Upload(e.FullPath);

            // Delete file
            File.Delete(e.FullPath);
        }
Exemple #13
0
        public async Task <IActionResult> DeleteFileByIdAsync(string userId, string fileId)
        {
            if (string.IsNullOrEmpty(fileId))
            {
                logger.LogError($"FileName not present {fileId} UserName {fileId}");
                throw new ArgumentException($"Please provide filename to delete {fileId}", nameof(fileId));
            }

            if (string.IsNullOrEmpty(userId))
            {
                logger.LogError($"UserName not present {userId} UserName {userId}");
                throw new ArgumentException($"Please provide userName to delete {userId}", nameof(userId));
            }

            try
            {
                string fileToDelete = $"{userId}/{fileId}";
                logger.LogInformation($"Deleting file {fileToDelete} for user {fileId}");
                BlobClient     blobClient = this.uploadsContainer.GetBlobClient(fileToDelete);
                BlobProperties props      = await blobClient.GetPropertiesAsync().ConfigureAwait(false);

                var str = blobClient.Uri;
                blobClient.DeleteIfExists();
                logger.LogInformation($"Deleted file  file {blobClient.Uri}");
                return(Ok($"{blobClient.Uri}"));
            }
            catch (Azure.RequestFailedException ex)
            {
                logger.LogError($"Received Exception {ex}");
                if (ex.Status == (int)HttpStatusCode.NotFound)
                {
                    return(NotFound(ex));
                }
                return(StatusCode(501));
            }
        }
        private static void DeleteBlob(string name)
        {
            BlobClient blob = container.GetBlobClient(name);

            blob.DeleteIfExists(DeleteSnapshotsOption.IncludeSnapshots);
        }