Closed ghost closed 10 years ago
can you give me a sample curl request?
Hi,
Don’t know anything about curl, I’m using a database application. However, if you use requestmaker.com and enter the URI as http://ogre.adc4gis.com/convert and then upload=C:\Users\Marcus\Desktop\crossings.zip as a parameter it gives the same response as I am getting in my application:
{"error":true,"msg":"Cannot read property 'upload' of undefined"}
See attached screenshots.
From: Marc Harter [mailto:notifications@github.com] Sent: 30 May 2014 21:41 To: wavded/ogre Cc: Marcus Young Subject: Re: [ogre] POst request (#27)
can you give me a sample curl request?
— Reply to this email directly or view it on GitHubhttps://github.com/wavded/ogre/issues/27#issuecomment-44697075.
are you setting the content type as form/multipart-data and sending up multipart POST data? Simply entering what you have isn't actually sending any file.
How would I do that? In the database application I only have the option to enter a uri and parameters.
From: Marc Harter Sent: Saturday, 31 May 2014 04:04 To: wavded/ogre Reply To: wavded/ogre Cc: Marcus Young Subject: Re: [ogre] POst request (#27)
are you setting the content type as form/multipart-data and sending up multipart POST data? Simply entering what you have isn't actually sending any file.
— Reply to this email directly or view it on GitHubhttps://github.com/wavded/ogre/issues/27#issuecomment-44716330.
It depends on the application and it may not be possible. Which database application are you working with if you can say?
It’s little known, called Brilliant Database.
From: Marc Harter [mailto:notifications@github.com] Sent: 02 June 2014 05:18 To: wavded/ogre Cc: Marcus Young Subject: Re: [ogre] POst request (#27)
It depends on the application and it may not be possible. Which database application are you working with if you can say?
— Reply to this email directly or view it on GitHubhttps://github.com/wavded/ogre/issues/27#issuecomment-44800857.
Hmm ok...
I'm not sure how much I can help you, as it stands, you are not sending proper multipart data through Brilliant nor that request generator you sent, and I don't know if that even feasible in that Brilliant.
The Ogre site itself has a form that generates the proper request as an example. How do you intend to use the data you get back inside Brilliant? Can it parse GeoJSON responses?
ýI could write a parser for it. But primarily I wanted the user to be able to select a shapefile and then click a button to get it converted to geojson for use in my application which uses openlayers.
From: Marc Harter Sent: Tuesday, 3 June 2014 04:03 To: wavded/ogre Reply To: wavded/ogre Cc: Marcus Young Subject: Re: [ogre] POst request (#27)
Hmm ok...
I'm not sure how much I can help you, as it stands, you are not sending proper multipart datahttp://tools.ietf.org/html/rfc2388 through Brilliant nor that request generator you sent, and I don't know if that even feasible in that Brilliant.
The Ogre site itself has a form that generates the proper request as an example. How do you intend to use the data you get back inside Brilliant? Can it parse GeoJSON responses?
— Reply to this email directly or view it on GitHubhttps://github.com/wavded/ogre/issues/27#issuecomment-44915296.
closing this issue for now, please reopen if there is anything more to add. as it stands, there must be a multipart post request sent from the client application
Hi Marc,
I found this issue closely related to the problem I ran into. I kept getting the error "Cannot read property 'path' of undefined" every time I tried to send the HTTP POST request to "http://ogre.adc4gis.com/convert". Could you please have a look at it and give me some hint on where I was wrong. I did use "multifpart-form" in the request.
Attached is a screenshot of the response from the server in the cmd window.
I pasted the JavaScript code I am working on here also (it looks bad here, so i will email a copy to you). Thanks in advance!
var http = require("http");
var fs = require("fs");
/* reproject GeoJsonFiles */
var sourceSrs = "EPSG:4326";
var targetSrs = "EPSG:900913";
var polylineFn = __dirname + '/sightings.geojson';
reprojectGeoJson(polylineFn, sourceSrs, targetSrs);
/*
* this function reproject a GeoJson Object
* Based on services @: http://ogre.adc4gis.com/
*/
function reprojectGeoJson(JsonFilename, sourceSrs, targetSrs) {
var boundary = Math.random().toString().substr(2);
// build data to post from an object
var jsonData;
var post_data = [];
var length = 0;
/* failed read file from file, DO NOT KNOW why
fs.readFile(JsonFilename, null, function (err, data) {
if (err) {
console.log('Error: ' + err);
return;
}
jsonData = data;
//jsonData = JSON.stringify(JSON.parse(data));
console.dir(typeof data);
console.dir(data);
});
*/
/* So I use this instead */
jsonData = JSON.stringify({"type": "FeatureCollection","features": [{"type": "Feature","properties": {
"species": "aaa",
"year": "aaa",
"month": "aaa",
"day": "aaa",
"name": "aaa",
"age": "aaa",
"occupation": "aaa",
"comments": "aaa."
},"geometry": {
"type": "Polygon",
"coordinates": [[
[
99.27576673096071,
26.339879886083548
],
[
99.28915631835989,
26.339572207437662
],
[
99.29808270996533,
26.33680306281198
],
[
99.30443418090775,
26.32787981279925
],
[
99.30134427612471,
26.32018680390223
],
[
99.29327619140993,
26.31680171809924
],
[
99.26563870972092,
26.32034066908849
],
[
99.27576673096071,
26.339879886083548
]
]
]
}
}
]
});
var dataObj = {
upload: jsonData,
sourceSrs: sourceSrs,
targetSrs: targetSrs
};
for(var key in dataObj) {
var value = dataObj[key];
// field part
if(key != "upload") {
var data = "";
data += "--" + boundary
+ "\r\nContent-Disposition: form-data; name=" + key
+ "\r\nContent-type: text/plain"
+ "\r\n\r\n" + value + "\r\n";
post_data.push(new Buffer(data, 'utf8'));
}
// file part
else{
var data = "";
data += "--" + boundary
+ "\r\nContent-Disposition: form-data; name=" + key
+ "\r\filename=" + JsonFilename
+ "\r\n Content-Type: application/octet-stream\r\n";
post_data.push(new Buffer(data, 'utf8'));
console.log(typeof value);
post_data.push(new Buffer(value, 'utf8'));
}
}
post_data.push(new Buffer("\r\n-- " + boundary + "-- ", 'utf8'));
// calculate length
for(var i = 0; i < post_data.length; i++) {
length += post_data[i].length;
}
// options to indicate where to post to
var options = {
host: "ogre.adc4gis.com",
port: "80",
path: "/convert",
method: "POST",
headers: {
// to upload a file, it must be this type
"Content-Type": "multipart/form-data, boundary=" + boundary,
"Content-Length": length
}
};
// Set up the request
var httpRequest = http.request(options, function(response) {
console.log('STATUS: ' + response.statusCode);
console.log('HEADERS: ' + JSON.stringify(response.headers));
response.setEncoding("utf8");
response.on("data", function (chunk) {
console.log('Body: ' + chunk);
});
});
httpRequest.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
// post the data
for (var i = 0; i < post_data.length; i++) {
httpRequest.write(post_data[i], 'utf8');
}
httpRequest.end();
}
Multipart can be tricky to get right. I would suggest saving yourself the work in Node and use a request building module like request
or superagent
. Here is a full example that works using superagent
.
sightings.geojson
is in the same directory as your script.npm install superagent
within the same directory as your script.Here's the script:
var request = require("superagent")
request
.post('http://ogre.adc4gis.com/convert')
.field('sourceSrs', 'EPSG:4326')
.field('targetSrs', 'EPSG:900913')
.attach('upload', __dirname+'/sightings.geojson')
.end(function (er, res) {
if (er) return console.error(er)
console.log(res.body)
})
Thanks!
This did save me. Can you also give me an example for the geojson to shapefile service?
I tried some thing like:
var request = require("superagent")
request .post('http://ogre.adc4gis.com/convertJson') .field('json', someJsonString) .field('outputName', 'myfile.zip') .end(function (er, res) { if (er) return console.error(er) console.log(res.body) })
But I kept getting empty res.body.... The response is there, but I do not know where/how I can get the .zip file.
On 7/30/2014 11:08 AM, Marc Harter wrote:
Multipart can be tricky to get right. I would suggest saving yourself the work in Node and use a request building module like |request| or |superagent|. Here is a full example that works using |superagent|.
- Ensure |sightings.geojson| is in the same directory as your script.
- Run |npm install superagent| within the same directory as your script.
Here's the script:
var request = require("superagent")
request .post('http://ogre.adc4gis.com/convert') .field('sourceSrs', 'EPSG:4326') .field('targetSrs', 'EPSG:900913') .attach('upload', __dirname+'/sightings.geojson') .end(function (er, res) { if (er) return console.error(er) console.log(res.body) })
Reply to this email directly or view it on GitHub https://github.com/wavded/ogre/issues/27#issuecomment-50568655.
Zhang, Guiming PhD student in GIScience Department of Geography, UW-Madison 550 N. Park Street Madison, WI, 53706-1491 Email: gzhang45@wisc.edu
Ahh, that request isn't a multipart. Here is one way you could do it. This will write the contents of the file out to myzip.zip
in the same directory as the script:
var request = require("superagent")
var fs = require('fs')
request
.post('http://ogre.adc4gis.com/convertJson')
.type('form')
.send({
json: JSON.stringify({
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"properties": {
"species": "aaa",
"year": "aaa",
"month": "aaa",
"day": "aaa",
"name": "aaa",
"age": "aaa",
"occupation": "aaa",
"comments": "aaa."
},
"geometry": {
"type": "Polygon",
"coordinates": [[[
99.27576673096071,
26.339879886083548
], [
99.28915631835989,
26.339572207437662
], [
99.29808270996533,
26.33680306281198
], [
99.30443418090775,
26.32787981279925
], [
99.30134427612471,
26.32018680390223
], [
99.29327619140993,
26.31680171809924
], [
99.26563870972092,
26.32034066908849
], [
99.27576673096071,
26.339879886083548
]]]
}
}]
}),
})
.pipe(fs.createWriteStream(__dirname+'/myzip.zip'))
I am trying to use ogre convert in my application, and calling this service from client side. I am trying to use OGRE online converter to convert shapefiles to different format, referring https://ogre.adc4gis.com/ I am making an AJAX call to send the file and get the response, but the response says "Cannot read property 'path' of undefined"
Below is the code snippet for ajax call, where sFile is the file from the file upload control. I tried to attach file in several methods for 'data' in ajax call (create FormData object, creating object etc), but I am getting the same error.
function shapeFileProcessing(sFile){
var formdata = new FormData();
formdata.append("upload", sFile);
var obj = {};
obj.upload = sFile;
$.ajax({
url : 'http://ogre.adc4gis.com/convert',
data : obj,
type : "POST",
success : function(msg) {
console.log("Success: "+msg);
}
});
}
I also tried with a form and submitting as it is in https://ogre.adc4gis.com/ but the result is redirecting to https://ogre.adc4gis.com/convert even if I have jsonpcallback. How can I use this in my client side application using ajax call?
Thanks in advance
Hi,
Trying to directly make an HTTP POST request and get this as a response:
{"error":true,"msg":"Cannot read property 'upload' of undefined"}
I'm providing the upload parameter with the local file location.