Page 1 of 2

How to Access File from Appery Database

Posted: Fri May 17, 2013 8:31 pm
by Stephen Goveia

Hi smart people! :) Trying to overly a polyline(route or track) from an uploaded .gpx file to my map component.

Database: spacetimeDB
Uploaded File Name: 100104 (gpx / xml file for GPS data)
map widget: googlemap_42

Here is my JS asset code. I call initialize(); on page Load.

function initialize() {
var race_ID_GPX = "100104";
var db_ID = "5187fbe2e4b0446b3349dffd";
var serverUrl = 'https://api.appery.io/rest/1/spacetim...'+ race_ID_GPX;

Code: Select all

       var mapOptions = { 

            zoom: 11, 
            mapTypeId: google.maps.MapTypeId.TERRAIN  
       };     

 var map = new google.maps.Map($('div[dsid="googlemap_42"]').get(0), mapOptions); 

 $.ajax({ 
            type: "GET", 
            url: serverUrl, 
            dataType: "xml", 
            success: function (xml) { 
                 var points = []; 
                 var bounds = new google.maps.LatLngBounds(); 
                 $(xml).find("trkpt").each(function () { 
                      var lat = $(this).attr("lat"); 
                      var lon = $(this).attr("lon"); 
                      var p = new google.maps.LatLng(lat, lon); 
                      points.push(p); 
                      bounds.extend(p); 
                 }); 
                 var poly = new google.maps.Polyline({ 
                      // Setting line Style 
                      path: points, 
                      strokeColor: "#007ED5", 
                      strokeOpacity: .7, 
                      strokeWeight: 4 
                 }); 
                 poly.setMap(map); 
                 // fit bounds to track 
                 map.fitBounds(bounds); 
            } 
       }); 
  } 

In the console I get this Error:

Failed to load resource: the server responded with a status of 405 (Method Not Allowed)
{"code":"BCXX004","description":"No resource method found for GET, return 405 with Allow header"}

Can you see anything wrong in my code that would cause this error?


How to Access File from Appery Database

Posted: Fri May 17, 2013 8:56 pm
by Maryna Brodina

Hello! You have incorrect URL. It should be codehttps://api.appery.io/rest/1/db/files/[fileName]/code
Please take a look here http://docs.appery.io/documentation/b...


How to Access File from Appery Database

Posted: Fri May 17, 2013 9:03 pm
by Stephen Goveia

Hi Marina!
https://api.appery.io/rest/1/spacetim...

Is what I just tried and it till gives me the 405 error


How to Access File from Appery Database

Posted: Fri May 17, 2013 9:05 pm
by Stephen Goveia

How to Access File from Appery Database

Posted: Fri May 17, 2013 9:06 pm
by Stephen Goveia

codehttps://api.appery.io/rest/1/spacetimeDB/files/100104/code

Sorry finally..


How to Access File from Appery Database

Posted: Fri May 17, 2013 9:12 pm
by Stephen Goveia

This didn't work either


How to Access File from Appery Database

Posted: Sun May 19, 2013 4:49 pm
by Stephen Goveia

Still getting "405" method error please look at my JS assest, am I setting everything up right?

code

function initialize() {
var race_ID_GPX = localStorage.getItem("raceIDLocalVar");
var db_ID = "5187fbe2e4b0446b33d6544ffd&quot
var serverUrl = 'https://api.appery.io/rest/1/spacetimeDB/files/'+ race_ID_GPX;
var session_token = localStorage.getItem('_sessionToken');

Code: Select all

       var mapOptions = { 

            zoom: 11, 
            mapTypeId: google.maps.MapTypeId.TERRAIN  
       };     

 var map = new google.maps.Map($('div[dsid="googlemap_42"]').get(0), mapOptions); 

 $.ajax({ 
            type: "GET", 
         headers: {'X-Appery-Database-ID':'db_ID','X-Appery-Session-Token':'session_token'}, 
            url: serverUrl, 
            dataType: "xml", 
            success: function (xml) { 
                 var points = []; 
                 var bounds = new google.maps.LatLngBounds(); 
                 $(xml).find("trkpt").each(function () { 
                      var lat = $(this).attr("lat"); 
                      var lon = $(this).attr("lon"); 
                      var p = new google.maps.LatLng(lat, lon); 
                      points.push(p); 
                      bounds.extend(p); 
                 }); 
                 var poly = new google.maps.Polyline({ 
                      // Setting line Style 
                      path: points, 
                      strokeColor: "#007ED5", 
                      strokeOpacity: .7, 
                      strokeWeight: 4 
                 }); 
                 poly.setMap(map); 
                 // fit bounds to track 
                 map.fitBounds(bounds); 
            } 
       }); 
  } 

/code


How to Access File from Appery Database

Posted: Mon May 20, 2013 7:29 am
by Maryna Brodina

Hello! There is no need to to change DB name in URL. It should be like this
codevar serverUrl = 'https://api.appery.io/rest/1/db/files/'+ race_ID_GPX;/code


How to Access File from Appery Database

Posted: Mon May 20, 2013 1:47 pm
by Stephen Goveia

Thank Marina, except now I am getting a 400 (Bad Request) error? All I did was change spacetimeDB to db. Others wise its exactly like my above code.


How to Access File from Appery Database

Posted: Mon May 20, 2013 2:08 pm
by Stephen Goveia

Console link says:

{"code":"DBFR002","description":"database id not specified"}