How do I retrieve the URL of a file hosted on Parse-Server through Javascript?

1.4k views Asked by At

My code so far:

<script type="text/javascript">
var username = sessionStorage.getItem('username', username);
var password = sessionStorage.getItem('password', password);
var Image = Parse.Object.extend("Image");
var query = new Parse.Query(Image);

query.equalTo("username", username);
query.descending("createdAt");

query.find({
  success: function(results) {
    alert("Successfully retrieved " + results.length + " images.");
    // Do something with the returned Parse.Object values
       for (var i = 0; i < results.length; i++) {
       var object = results[i];
       var url = (object.get("image").url);
       var createdAt = (object.get("createdAt"));
       var image = object.get("image");
       alert(url + object.id + createdAt + username + image);
    }
  },
  error: function(error) {
    alert("Error: " + error.code + " " + error.message);
  }
});
</script>

All variables return the expected values except "image" which returns [Object object] and url which returns function url(){ return this._url;}

1

There are 1 answers

0
Ran Hassid On

in order to get the file URL you need to do the following :

var image = object.get("image"); // here you have ParseFile
var imageUrl = image.url();  // now you have the file URL