I am trying to use haxr 3000.8.5 to upload images to a WordPress blog using the metaWeblog API --- specifically, newMediaObject .
I got it for working with small images by successfully loading 20x20 icons in PNG and JPG formats. However, when I try to use medium-sized images (say 300x300), I get an ErrorClosed exception, presumably from HTTP (I used the diving source a bit, and found that haxr ended up calling Network.HTTP.simpleHTTP ).
Can anyone shed some light on the reasons why a simpleHTTP call might fail using ErrorClosed ? Suggestions for attempts and possible workarounds are also welcome.
Below are links to the full output of tcpdump from a successful download and from a failed download .
The code (sanitized) is also shown below, if used.
import Network.XmlRpc.Client (remote) import Network.XmlRpc.Internals (Value(..), toValue) import Data.Char (toLower) import System.FilePath (takeFileName, takeExtension) import qualified Data.ByteString.Char8 as B import Data.Functor ((<$>)) uploadMediaObject :: FilePath -> IO Value uploadMediaObject file = do media <- mkMediaObject file remote "http://someblog.wordpress.com/xmlrpc.php" "metaWeblog.newMediaObject" "default" "username" "password" media -- Create the required struct representing the image. mkMediaObject :: FilePath -> IO Value mkMediaObject filePath = do bits <- B.unpack <$> B.readFile filePath return $ ValueStruct [ ("name", toValue fileName) , ("type", toValue fileType) , ("bits", ValueBase64 bits) ] where fileName = takeFileName filePath fileType = case (map toLower . drop 1 . takeExtension) fileName of "png" -> "image/png" "jpg" -> "image/jpeg" "jpeg" -> "image/jpeg" "gif" -> "image/gif" main = do v <- uploadMediaObject "images/puppy.png" print v
Brent yorgey
source share