Amazon S3 bucket sub objects REST and Java without SDK -


i want list of objects , folders in bucket in amazon s3 can't, should not use amazon s3 sdk.

it's important not use sdk , rest , java should sent request , receive response. have method :

public string bucketsublist(string strpath) throws exception {      string answer = null;      // s3 timestamp pattern.     string fmt = "eee, dd mmm yyyy hh:mm:ss ";     simpledateformat df = new simpledateformat(fmt, locale.us);     df.settimezone(timezone.gettimezone("gmt"));      // data needed signature     string method = "get";     string contentmd5 = "";     string contenttype = "";     string date = df.format(new date()) + "gmt";     string bucket = "/" + strpath + "/";      // generate signature     stringbuffer buf = new stringbuffer();     buf.append(method).append("\n");     buf.append(contentmd5).append("\n");     buf.append(contenttype).append("\n");     buf.append(date).append("\n");     buf.append(bucket);     // try {     string signature = sign(buf.tostring());      // connection s3.amazonaws.com     url url = new url("http", "s3.amazonaws.com", 80, bucket);      httpurlconnection httpconn = null;     httpconn = (httpurlconnection) url.openconnection();     httpconn.setdoinput(true);     httpconn.setdooutput(true);     httpconn.setusecaches(false);     httpconn.setdefaultusecaches(false);     httpconn.setallowuserinteraction(true);     httpconn.setrequestmethod(method);     httpconn.setrequestproperty("date", date);     // httpconn.setrequestproperty("content-type", "text/plain");      string awsauth = "aws " + keyid + ":" + signature;     httpconn.setrequestproperty("authorization", awsauth);      // send http put request.     int statuscode = httpconn.getresponsecode();     system.out.println(statuscode);     if ((statuscode / 100) != 2) {         // deal s3 error stream.         inputstream in = httpconn.geterrorstream();         string errorstr = gets3errorcode(in);         system.out.println("error: " + errorstr);     } else {         answer = "";         // system.out.println("bucket listed successfully");         inputstream inst = httpconn.getinputstream();         bufferedreader in = new bufferedreader(new inputstreamreader(inst));         string decodedstring;         while ((decodedstring = in.readline()) != null) {             answer += decodedstring;             system.out.println(answer);         }         in.close();     }      return answer; } 

without knowing problem is, can give link aws s3 rest api.

this method want.

i hope might you.

otherwise please give more information problem.


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -