Exemplo n.º 1
0
        public string Post([FromBody] imageUploadModel model)
        {
            try {
                string output;

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(model.targetURL);
                request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;

                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                    using (Stream stream = response.GetResponseStream())
                        using (StreamReader reader = new StreamReader(stream))
                        {
                            output = reader.ReadToEnd();
                        }
                JObject json = JObject.Parse(output);
                string  name = (string)json.SelectToken("name");
                name = name.Replace("/", "%2F");
                string token = (string)json.SelectToken("downloadTokens");


                string downloadURL = "https://firebasestorage.googleapis.com/v0/b/annualsumm.appspot.com/o/" + name + "?alt=media&token=" + token;

                model.downloadURL = downloadURL;
                return(downloadURL);
            }
            catch (Exception ex)
            {
                return(ex.StackTrace);
            }
        }
Exemplo n.º 2
0
        public string Post(imageUploadModel model)
        {
            try {
                var    stream = System.IO.File.Open(model.filepath, FileMode.Open);
                Random random = new Random();
                int    number = random.Next(50);
                var    name   = RandomString(number);
                name = name + ".png";

                var task = new FirebaseStorage("annualsumm.appspot.com")
                           .Child("data")
                           .Child("summit")
                           .Child(name)
                           .PutAsync(stream);

                task.Progress.ProgressChanged += (s, e) => Console.WriteLine($"Progress: {e.Percentage} %");
                var downloadUrl = task;
                var targetURL   = task.TargetUrl; //save this somewhere and use it to get the download link
                model.targetURL = targetURL;
                return(targetURL);
            }
            catch (Exception ex)
            {
                return(ex.StackTrace);
            }
        }