Skip to content

Instantly share code, notes, and snippets.

@rodolfofadino
Created June 17, 2015 22:29
Show Gist options
  • Save rodolfofadino/bef134523421581a09c7 to your computer and use it in GitHub Desktop.
Save rodolfofadino/bef134523421581a09c7 to your computer and use it in GitHub Desktop.
Upload Image on Thumbor with c#
class Program
{
static void Main(string[] args)
{
var httpClient = new HttpClient();
var httpContent = new ByteArrayContent(FileToByteArray(@"C:\deborah-secco.jpg"));
httpContent.Headers.Add("slug", "deborah-secco.jpg");
HttpResponseMessage response = null;
try
{
httpContent.Headers.Add("Content-Type", "image/jpg");
response = httpClient.PostAsync("http://thumbor-server/image", httpContent).Result;
}
catch (HttpRequestException request_Exception)
{
}
}
private static byte[] FileToByteArray(string _FileName)
{
byte[] _Buffer = null;
try
{
System.IO.FileStream _FileStream = new System.IO.FileStream(_FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
System.IO.BinaryReader _BinaryReader = new System.IO.BinaryReader(_FileStream);
long _TotalBytes = new System.IO.FileInfo(_FileName).Length;
_Buffer = _BinaryReader.ReadBytes((Int32)_TotalBytes);
_FileStream.Close();
_FileStream.Dispose();
_BinaryReader.Close();
}
catch (Exception _Exception)
{
// Error
}
return _Buffer;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment