I have a GeoTIFF already available in GeoServer DATA_DIR, specifically in a subdir named "rice" and I woluld like to publish it as a CoverageStore.

What I could understand is that REST API allows to create the coverage with a PUT request passing the file as the payload. How can I skip this step? The only documented option seem to allow for just the 'file[.extension]' option that requires passing in a file. On the other side, datastores allow for an 'external' option that allows picking from DATA_DIR.


The key point is using the PUT method and send a request with both a payload and a couple of querystring parameters.

Most notably, is that there is no need to move GeoTIFF coverage to GeoServer Data DIR provided that the GeoServer instance (so its container - e.g. Tomcat) can reach the GeoTIFF file in Server's filesystem.

So it is just a matter of composing into the HttpPut instance a StringEntity holding the absolute path to the GeoTIFF file.

String REST_API_URL = "http://localhost:8080/geoserver/rest";
String workspacename = "myworkspace";
String coveragestorename = "mygeotiffname";
String coverageFormat  = "geotiff";

String url = REST_API_URL + "/workspaces/" + workspacename
    + "/coveragestores/" + coveragestorename
    + "/external."+ coverageFormat
    + "?configure=first&coverageName=" + coveragestorename ;
HttpPut request = // here create an org.apache.http.client.methods.HttpPut instance
                  // including Basic Auth
request.setHeader(HttpHeaders.CONTENT_TYPE, "text/plain");
String data = // here provide ABSOLUTE path to GeoTIFF file;
StringEntity entity = new StringEntity(data, ContentType.create("text/plain", Consts.UTF_8));
CloseableHttpClient client = HttpClientBuilder.create().build();
HttpResponse response = client.execute(request);
int responseCode = response.getStatusLine().getStatusCode();

The returned responseCode should be 201 (HttpStatus.SC_CREATED)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.