Example #1
0
        public async Task <string> GetFile(string path)
        {
            try
            {
                var fileDirectory = baseDirectory + "AppFiles/TempFiles/";
                if (!Directory.Exists(fileDirectory))
                {
                    Directory.CreateDirectory(fileDirectory);
                }

                var newFilePath = fileDirectory + Path.GetFileName(path);
                if (File.Exists(newFilePath))
                {
                    return(newFilePath);
                }

                var result = await _httpService.GetApiResultByte($"{baseUrl}/GetFile?path={path}");

                if (ReferenceEquals(result, null))
                {
                    return(String.Empty);
                }

                await File.WriteAllBytesAsync(newFilePath, result);

                return(newFilePath);
            }
            catch
            {
                return(null);
            }
        }