Exemple #1
0
        private static async Task DeleteFile(string pathToFile)
        {
            var fileName = Path.GetFileName(pathToFile);
            var folder   = GetPathWithoutFileName(pathToFile);

            using (var client = new HttpClientWithAuth())
            {
                var urlWithQueryString = $"{_fileApiUrl}?fileName={pathToFile}";

                var response = await client.DeleteAsync(urlWithQueryString);

                if (!response.IsSuccessStatusCode)
                {
                    throw new Exception($"Failed to delete {pathToFile}.");
                }
            }
        }
Exemple #2
0
        private static async Task <List <string> > GetFileList(string folder)
        {
            using (var client = new HttpClientWithAuth())
            {
                var urlWithQueryString = $"{_fileApiUrl}/List?directory={folder}";

                var response = await client.GetAsync(urlWithQueryString);

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    return(JsonConvert.DeserializeObject <List <string> >(await response.Content.ReadAsStringAsync()));
                }

                if (response.StatusCode == HttpStatusCode.NotFound)
                {
                    return(null);
                }

                throw new Exception($"Failed to get list of files in {folder}.");
            }
        }
Exemple #3
0
        private static async Task WriteFileContent(string pathToFile, string content)
        {
            using (HttpClientWithAuth client = new HttpClientWithAuth())
            {
                var url = $"{_fileApiUrl}api/S3/File";

                var form = new MultipartFormDataContent
                {
                    { new StringContent(pathToFile), "fileName" },

                    //{ new ByteArrayContent(Encoding.UTF8.GetBytes(content)), "file", pathToFile }
                    { new StringContent(content), "file", pathToFile }
                };

                var response = await client.PostAsync(_fileApiUrl, form);

                if (response.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    throw new Exception($"Failed to upload {pathToFile}.");
                }
            }
        }
Exemple #4
0
        private static async Task <string> GetFileContent(string pathToFile)
        {
            var fileName = Path.GetFileName(pathToFile);
            var folder   = GetPathWithoutFileName(pathToFile);

            using (var client = new HttpClientWithAuth())
            {
                var urlWithQueryString = $"{_fileApiUrl}?fileName={pathToFile}";

                var response = await client.GetAsync(urlWithQueryString);

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    return(await response.Content.ReadAsStringAsync());
                }

                if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    return(null);
                }

                throw new Exception($"Failed to download {fileName}.");
            }
        }