Wednesday, May 9, 2012

Ruby: uploading image problem, getting Internal server error

There is one thing you need to remember while uploading image using Ruby. You have to read the file in binary mode. Otherwise for some server, you'll get Internal server error. I am giving you an example using the Ruby/Mechanize.

File.open(imgFile, "rb") do|binaryImage|
content = a.post('http://example.com/uploadImage.php',
{
:img => binaryImage,
:imgTitle => 'some title'
});
end

Here,
imgFile is the path to your image.
"rb" used inside file open for reading file as binary mode.

No comments:

Get function name programaticaly - Python

This little piece of code will help you to get the function name programatically. This is very helpful when you are implementing the debug...