如何通过Javascript检索Parse-Server上托管的文件的URL?

时间:2016-12-17 07:40:42

标签: parse-server

到目前为止我的代码:

<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>

除了返回[Object object]的“image”和返回function url(){ return this._url;}

的url之外,所有变量都返回预期值

1 个答案:

答案 0 :(得分:0)

要获取文件URL,您需要执行以下操作:

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