jsp - Uploading WordPress media files using XML-RPC -


this code.

    public void fileupload() throws exception {          byte filebyte[] =org.apache.commons.io.fileutils.readfiletobytearray(new file(path+realname));                 string wpupfile=filetostring(new file(path+realname));                 xmlrpcclient blog  = new xmlrpcclient();                 xmlrpcclientconfigimpl config = new xmlrpcclientconfigimpl();                 hashtable<string, string> post = new hashtable<>();                 vector<serializable> params = new vector<serializable>();                 config.setserverurl(url);                 config.setbasicusername(user);                 config.setbasicpassword(pw);                 params.addelement(id);                 params.addelement(user);                 params.addelement(pw);                 post.put("name", realname);                 post.put("type", "image/jpeg");                 post.put("bits", wpupfile);                 post.put("overwrite", "false");                 params.addelement(post);                 params.addelement(true);                 object blogpostid = blog.execute(config, "wp.uploadfile", params);     } 

file base64 change code

 public string filetostring(file file) throws ioexception {                 string filestring = new string();                 fileinputstream inputstream =  null;                 bytearrayoutputstream byteoutstream = null;                 try {                     inputstream = new fileinputstream(file);                     byteoutstream = new bytearrayoutputstream();                     int len = 0;                     byte[] buf = new byte[1024];                         while ((len = inputstream.read(buf)) != -1) {                              byteoutstream.write(buf, 0, len);                     }                     byte[] filearray = byteoutstream.tobytearray();                     filestring = new string(base64.encodebase64(filearray));                 } catch (ioexception e) {                     e.printstacktrace();                 } {                     inputstream.close();                     byteoutstream.close();                 }                return filestring;     } 

result

enter image description here

the image file not displayed properly. problem? dont know why errors happend. please let me know. please me.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -