basically i've been using these particular lines of code quite time , never had problems it. nothing's been touched i'm getting
illegalstateexception - connected
exactly after set conn.setusescaches(false)
public void putimagetos3(string signedurl, bitmap image) throws wampnetworkexception, ioexception { url url = new url(signedurl); httpurlconnection conn = (httpurlconnection) url.openconnection(); conn.getdooutput(); conn.setusecaches(false); conn.setrequestmethod("put"); conn.addrequestproperty("content-type", "image/jpeg"); conn.addrequestproperty("connection", "close"); outputstream out = new bufferedoutputstream(conn.getoutputstream()); image.compress(bitmap.compressformat.jpeg, 100, out); if (conn.getresponsecode() != httpurlconnection.http_ok) { throw new ioexception("failed upload image s3: " + conn.getresponsecode() + conn.getresponsemessage() + "\r\n"); } out.flush(); out.close(); conn.disconnect(); }
write code in try-finally block , try
public void putimagetos3(string signedurl, bitmap image) throws wampnetworkexception, ioexception { try{ url url = new url(signedurl); httpurlconnection conn = (httpurlconnection) url.openconnection(); conn.getdooutput(); conn.setusecaches(false); conn.setrequestmethod("put"); conn.addrequestproperty("content-type", "image/jpeg"); conn.addrequestproperty("connection", "close"); outputstream out = new bufferedoutputstream(conn.getoutputstream()); image.compress(bitmap.compressformat.jpeg, 100, out); if (conn.getresponsecode() != httpurlconnection.http_ok) { throw new ioexception("failed upload image s3: " + conn.getresponsecode() + conn.getresponsemessage() + "\r\n"); } } finally{ out.flush(); out.close(); conn.disconnect(); } }
Comments
Post a Comment