Пример #1
0
        public override UploadResult Upload(Stream stream, string fileName)
        {
            Dictionary <string, string> arguments = new Dictionary <string, string>();

            arguments.Add("apikey", API_KEY);
            arguments.Add("familysafe", "0"); // Set to 0 as images could possibly not be family safe.

            UploadResult result = UploadData(stream, API_ENDPOINT, fileName, "file", arguments);

            if (result.IsSuccess)
            {
                if (!string.IsNullOrEmpty(result.Response))
                {
                    SomeImageResponse jsonResponse = JsonConvert.DeserializeObject <SomeImageResponse>(result.Response);

                    if (jsonResponse != null)
                    {
                        if (DirectURL)
                        {
                            if (!string.IsNullOrEmpty(jsonResponse.imagelink))
                            {
                                Uri    responseUri = new Uri(jsonResponse.imagelink);            // http://someimage.com/asdf
                                string host        = responseUri.Host;                           // someimage.com
                                string filename    = Path.GetFileName(responseUri.AbsolutePath); // /asdf
                                if (filename.StartsWith("/"))
                                {
                                    filename = filename.Remove(0, 1); // asdf
                                }
                                if (host.StartsWith("www."))
                                {
                                    host = host.Remove(0, 4);
                                }
                                string extension = Path.GetExtension(fileName);
                                result.URL = $"https://i1.{host}/{filename}{extension}";
                            }
                        }
                        else
                        {
                            result.URL = jsonResponse.imagelink;
                        }
                    }
                }
            }

            return(result);
        }
Пример #2
0
        public override UploadResult Upload(Stream stream, string fileName)
        {
            Dictionary <string, string> arguments = new Dictionary <string, string>();

            arguments.Add("apikey", API_KEY);
            arguments.Add("familysafe", "0"); // Set to 0 as images could possibly not be family safe.

            UploadResult result = UploadData(stream, API_ENDPOINT, fileName, "file", arguments);

            if (result.IsSuccess)
            {
                if (!string.IsNullOrEmpty(result.Response))
                {
                    SomeImageResponse jsonResponse = JsonConvert.DeserializeObject <SomeImageResponse>(result.Response);

                    if (jsonResponse != null)
                    {
                        result.URL = jsonResponse.imagelink;
                    }
                }
            }

            return(result);
        }