Get metadata of Object

The HEAD object of QueryIO server fetches the metadata from an object. This is useful if user is only interested in metadata of object, since it does not return the object itself.

S3 Compatible REST API Sample

Following code is used to perform HEAD object operation.

HttpURLConnection object creates a HEAD request to access an object from the bucket. URL appended with objectName is used with HttpURLConnection object. On successful completion, a HttpStatus.SC_OK response code is received.


import org.apache.http.HttpStatus;

public class ObjectOperations {
	 	 * This program retrieves a object from the bucket
		 * @param serverURL: URL of S3 Compatible REST server(http://<S3 server IP> : <S3 server port> /queryio/). For example:
		 * @param token: authorization token.
		 * @param bucketName: Name of the bucket from which object will be retrieved
		 * @param objectName: Name of the object whose metadata will be retrieved
		public void getObject(String serverURL, String token, String bucketName,
			String objectName) throws Exception {
		URL url = null;
		HttpURLConnection httpCon = null;
		InputStream is = null;
		try {
			/* append "/" at end of serverURL */
			if (!serverURL.endsWith("/")) {
				serverURL = serverURL + "/";
			url = new URL(serverURL + bucketName + "/" + objectName);	//creates a URL with appending bucket name and objectName

			//Returns a URLConnection object that represents a connection to the remote object referred to by the URL.
			httpCon = (HttpURLConnection) url.openConnection();			
			httpCon.setDoOutput(true);	// to use the URL connection for output
			httpCon.setRequestMethod("HEAD");	//HEAD request is used

			httpCon.setRequestProperty("authorization", token);	//Provides token for authorization

			httpCon.connect();	//Opens a communications link to the resource reference by the URL

			if (httpCon.getResponseCode() == HttpStatus.SC_OK) {	//OK response for successful GET Object request
				 for (int i = 0;; i++) {
					 String headerName = httpCon.getHeaderFieldKey(i);
				      String headerValue = httpCon.getHeaderField(i);
				      if (headerName == null && headerValue == null) {
				      System.out.println(headerName + " : " + headerValue);

		} finally {
			try {	
				if (is != null)
					is.close();	//close stream
			} catch (IOException e) {
			if (httpCon != null) {
				httpCon.disconnect();	//close connection

Copyright 2017 QueryIO Corporation. All Rights Reserved.

QueryIO, "Big Data Intelligence" and the QueryIO Logo are trademarks of QueryIO Corporation. Apache, Hadoop and HDFS are trademarks of The Apache Software Foundation.