Example #1
0
        public Resource UploadImage(string path, int maxwidth, int maxheight)
        {
            //FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read);
            //int length = Convert.ToInt32(file.Length);
            //byte[] data = new byte[length];
            //file.Read(data, 0, length);
            //file.Close();
            string base64 = GetImageCompressBaseString(path, maxwidth, maxheight);

            Resource resource = new Resource()
            {
                Data = base64,
                Name = "imagename :3",
                Type = 1
            };

            using (HttpClient client = new HttpClient())
            {
                string url = Ultils.getUrl();
                client.BaseAddress = new Uri(url);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AppInstance.getInstance().GetUser().Token);
                HttpResponseMessage response = client.PostAsJsonAsync("/api/Resources", resource).Result;
                if (response.IsSuccessStatusCode)
                {
                    Resource res = response.Content.ReadAsAsync <Resource>().Result;
                    return(res);
                }
            }
            return(null);
        }
Example #2
0
 public string getImageResourceBaseString(long id)
 {
     using (HttpClient client = new HttpClient())
     {
         string url = Ultils.getUrl();
         client.BaseAddress = new Uri(url);
         client.DefaultRequestHeaders.Accept.Clear();
         client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
         client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AppInstance.getInstance().GetUser().Token);
         HttpResponseMessage response = client.GetAsync("/api/Resources/" + id).Result;
         if (response.IsSuccessStatusCode)
         {
             Resource res = response.Content.ReadAsAsync <Resource>().Result;
             return(res.Data);
         }
     }
     return("");
 }
Example #3
0
 public string getUserBase64Image(long id)
 {
     if (_dirUserImage.ContainsKey(id))
     {
         return(_dirUserImage[id]);
     }
     else
     {
         long imgid = 0;
         using (HttpClient client = new HttpClient())
         {
             string url = Ultils.getUrl();
             client.BaseAddress = new Uri(url);
             client.DefaultRequestHeaders.Accept.Clear();
             client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
             client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AppInstance.getInstance().GetUser().Token);
             HttpResponseMessage response = client.GetAsync("/api/Users/" + id).Result;
             if (response.IsSuccessStatusCode)
             {
                 User res = response.Content.ReadAsAsync <User>().Result;
                 imgid = res.Avatar;
             }
         }
         if (imgid != 0)
         {
             return(getImageResourceBaseString(imgid));
         }
         else
         {
             return("");
         }
     }
 }