예제 #1
0
        public static long?NewFile(StorageServiceConfiguation settings, IFormFile file)
        {
            using (var client = new System.Net.Http.HttpClient())
            {
                client.BaseAddress = new Uri(settings.BaseUrl);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Add("api-version", "1.0");

                byte[] data;
                using (var br = new BinaryReader(file.OpenReadStream()))
                {
                    data = br.ReadBytes((int)file.OpenReadStream().Length);
                }

                ByteArrayContent         bytes        = new ByteArrayContent(data);
                MultipartFormDataContent multiContent = new MultipartFormDataContent();

                multiContent.Add(bytes, "file", file.FileName);

                HttpResponseMessage response = client.PostAsync(settings.ResourceRoot + "/files", multiContent).Result;
                if (!response.IsSuccessStatusCode)
                {
                    return(null);
                }
                string stringData = response.Content.ReadAsStringAsync().Result;

                return(Convert.ToInt64(stringData));
            }
        }
예제 #2
0
        public static FileStream GetFileStream(StorageServiceConfiguation settings, long fileId)
        {
            using (var client = new System.Net.Http.HttpClient())
            {
                client.BaseAddress = new Uri(settings.BaseUrl);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Add("api-version", "1.0");

                HttpResponseMessage response = client.DeleteAsync(settings.ResourceRoot + "/files/" + fileId.ToString()).Result;
                if (response.IsSuccessStatusCode)
                {
                    string stringData = response.Content.ReadAsStringAsync().Result;
                    return(null); /// TODO return Convert.ToBoolean(stringData);
                }

                return(null);
            }
        }
예제 #3
0
 public EventDownloadsController(IOptions <ApiSettings> settings)
 {
     this._eventSettings   = settings.Value.EventService;
     this._storageSettings = settings.Value.StorageService;
 }
예제 #4
0
        public static FileStream GetFileStream(EventServiceConfiguration settingsEventService, StorageServiceConfiguation settingsStorrageService, long downloadId)
        {
            EventDownload download = null;

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(settingsEventService.BaseUrl);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                client.DefaultRequestHeaders.Add("api-version", "1.0");
                HttpResponseMessage response = client.GetAsync(settingsEventService.ResourceRoot + "/downloads/" + downloadId.ToString()).Result;
                if (response.IsSuccessStatusCode)
                {
                    string stringData = response.Content.ReadAsStringAsync().Result;
                    download = JsonConvert.DeserializeObject <EventDownload>(stringData);
                }
            }

            if (download == null)
            {
                return(null);
            }

            return(Services.Storages.Files.GetFileStream(settingsStorrageService, download.StorageServiceFileId));
        }