无法从Parse获取图像URL

时间:2021-07-18 20:52:34

I am having a hard time trying to retrieve an image URL that I am saving and writing to parse like so:

我很难尝试检索我正在保存的图像URL并写入解析,如下所示:

 var fileUploadControl = document.getElementById('img1');
 var file = fileUploadControl.files[0];
 var name = "icon.png";
 var iconImageFile = new Parse.File(name, file);
 iconImageFile.save().then(function() {
     var user = Parse.User.current();
     var url = iconImageFile.url();
     user.set('imagePicture', url);
     user.save();
});

This all works fine and dandy. And at this point I am able to retrieve this value by saying:

这一切都很好,花花公子。此时我可以通过以下方式检索此值:

var myImage = Parse.User.current().get('imagePicture');
console.log(myImage) // returns 'http://files.parsetfss.com/../icon.png'

However, when I refresh the page and the user is still signed in, when I go to retrieve this image by the same method:

但是,当我刷新页面并且用户仍然登录时,当我通过相同的方法检索此图像时:

var myImage = Parse.User.current().get('imagePicture');
console.log(myImage) // returns null

It returns null. I am able to get any other user values such as email, username, color, etc, but it gets hung up on an image; which is just a string to my knowledge. It must be a very simple issue that I am overlooking. Any ideas?

它返回null。我能够获得任何其他用户值,如电子邮件,用户名,颜色等,但它会挂在图像上;这只是我知道的一个字符串。它一定是一个我忽略的非常简单的问题。有任何想法吗?

2 个解决方案

#1


0  

The call to save is asynchronous, meaning that it will set imagePicture sometime in the future. You need to ensure that the function has been called before retiring imagePicture.

对save的调用是异步的,这意味着它将来会在某个时候设置imagePicture。您需要确保在退出imagePicture之前已调用该函数。

#2


0  

I was able to solve for it. Looks like I needed to use the fetch method instead:

我能够解决它。看起来我需要使用fetch方法:

Parse.User.current().fetch().then(function (user) {
    console.log(user.get('imagePicture'));
});

#1


0  

The call to save is asynchronous, meaning that it will set imagePicture sometime in the future. You need to ensure that the function has been called before retiring imagePicture.

对save的调用是异步的,这意味着它将来会在某个时候设置imagePicture。您需要确保在退出imagePicture之前已调用该函数。

#2


0  

I was able to solve for it. Looks like I needed to use the fetch method instead:

我能够解决它。看起来我需要使用fetch方法:

Parse.User.current().fetch().then(function (user) {
    console.log(user.get('imagePicture'));
});