GeoServer – Unable to Publish a GeoTiff File in GeoServer Using Curl Tool

apachegeoservergeoserver-rest-apigeotiff-tifftomcat

I have a workspace in GeoServer with many shapefiles and postgis tables. Now I'm writing a script that will publish GeoTiff files in that workspace using curl tool. I'm trying to succeed that in two steps.
At first I create a coveragestore with the following command:

curl -u admin:geoserver -v -XPOST -H 'Content-type: application/xml' -d '<coverageStore><name>input.tif</name><workspace>myworkspacee</workspace><enabled>true</enabled><type>GeoTIFF</type><url>/usr/share/geoserver/data/data/myworkspace/input.tif </url></coverageStore> http://my_mv_ip/geoserver/rest/workspaces/myworkspace/coveragestores'

which works fine. And then I execute:

curl -u admin:geoserver -v -XPUT -H "Content-type: image/tiff"  \
--data-binary @input.tif   \
http://my_vm_ip/geoserver/rest/workspaces/myworkspace/coveragestores/input/input.geotiff

The output from both commands in command line is the following:

Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying my_mv_ip...
* Connected to my_mv_ip (my_mv_ip) port 80 (#0)
* Server auth using Basic with user admin`
> POST /geoserver/rest/workspaces/myworkspace/coveragestores HTTP/1.1
> Host: my_mv_ip
> Authorization: Basic YWRtaW46Z2Vvc2VydmVy
> User-Agent: curl/7.47.0
> Accept: */*
> Content-type: application/xml
> Content-Length: 249 
> 
* upload completely sent off: 249 out of 249 bytes
< HTTP/1.1 201 Created
< Date: Mon, 14 Aug 2017 13:11:28 GMT
< Server: Noelios-Restlet-Engine/1.0..8
< Location: http://my_mv_ip/geoserver/rest/workspaces/myworkspace    /coveragestores/input
< Transfer-Encoding: chunked
< 
* Connection #0 to host my_vm_ip left intact
*   Trying my_mv_ip...
* Connected to my_mv_ip (my_mv_ip) port 80 (#0)
* Server auth using Basic with user admin
> PUT /geoserver/rest/workspaces/myworkspace/coveragestores/input    /input.geotiff 
HTTP/1.1
> Host: my_mv_ip
> Authorization: Basic YWRtaW46Z2Vvc2VydmVy
> User-Agent: curl/7.47.0
> Accept: */*
> Content-type: image/tiff
> Content-Length: 44295940
> Expect: 100-continue
> 
< HTTP/1.1 100 Continue 

After about 20 minutes it raises the following error:

We are completely uploaded and fine
< HTTP/1.1 502 Bad Gateway
< Date: Mon, 14 Aug 2017 12:10:44 GMT
< Server: Apache/2.4.7 (Ubuntu)
< Content-Length: 311
< Content-Type: text/html; charset=iso-8859-1 
< 
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>502 Bad Gateway</title>
</head><body>
<h1>Bad Gateway</h1>
<p>The proxy server received an invalid
response from an upstream server.<br />
</p>
<hr>
<address>Apache/2.4.7 (Ubuntu) Server at my_vm_ip Port 80</address>
</body></html>
* Connection #0 to host my_vm_ip left intact

I tried some solutions from:
Adding a new Coveragestore in a certain Workspace by REST
and:

Programming Geoserver 2.0.2 to add a raster data store and layer without the UI

But with no result. I'm using GeoServer 2.7.4 Tomcat7 and Ubuntu 14.04.

My Apache logs:

[Mon Aug 14 17:14:04.785741 2017] [proxy:error] [pid 14922:tid             139798341732096] (104)Connection reset by peer: [client 176.92.115.36:34098]     AH01084: pass request body failed to [::1]:8080 (localhost)
[Mon Aug 14 17:14:04.785886 2017] [proxy_http:error] [pid 14922:tid    139798341732096] [client 176.92.115.36:34098] AH01097: pass request body     failed to [::1]:8080 (localhost) from 176.92.115.36 ()

A piece from my tomcat logs:

14 Aug 17:14:04 ERROR [geoserver.rest] - Could not determine format. Try  setting the Content-type header. 
14 Aug 17:14:04 ERROR [geoserver.rest] -

Best Answer

Finally I found the answer in my question. It helped me the following topic: http://osgeo-org.1560.x6.nabble.com/Geoserver-REST-Question-td3796644.html and the answer of @iant because I figured out that the solution should be in front of my eyes.

Instead of:

curl -u admin:geoserver -v -XPUT -H "Content-type: image/tiff"  \
--data-binary @input.tif   \
http://my_vm_ip/geoserver/rest/workspaces/myworkspace/coveragestores/input/input.geotiff

I had to type:

curl -u admin:geoserver -v -XPUT -H "Content-type: image/tiff"  \
--data-binary @input.tif   \
http://my_vm_ip/geoserver/rest/workspaces/myworkspace/coveragestores/input/file.geotiff

In other words, I had just to replace input.geotiff with file.geotiff. And the problem solved. :-)

Related Question