Wednesday, May 9, 2012

Ruby: uploading image problem, getting Internal server error


Share at Facebook

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: