如何使用javascript存储然后从Parse中检索图像
How to store and then retrieve image from Parse using javascript
正如标题所解释的那样,我正在尝试将图像保存到Parse,然后检索该图像并将其显示为个人资料图片。现在,当我运行代码时,它不执行任何操作(显然,因为有些地方不对(。我做了广泛的研究,只是不断接近,但最终空手而归。任何人都可以为我提供一些指导,甚至是我的代码的某种修复吗?我知道我很接近。谢谢!
.HTML:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<script src="http://www.parsecdn.com/js/parse-1.2.12.min.js"></script>
<meta charset=utf-8 />
<title>Example</title>
</head>
<body ng-app="AuthApp">
<div ng-hide="currentUser">
<form ng-show="scenario == 'Sign up'">
<h2>Sign up</h2>
Picture: <input type="file" id="picture"/><br />
Email: <input type="email" ng-model="user.email" /><br />
Username: <input type="text" ng-model="user.username" /><br />
Password: <input type="password" ng-model="user.password" /><br />
First Name: <input type="text" ng-model="user.firstName" /><br />
Last Name: <input type="text" ng-model="user.lastName" /><br />
Mobile Number: <input type="text" ng-model="user.mobile" /><br />
Date of Birth:<input type="text" ng-model="user.dob" /><br />
<button ng-click="signUp(user)">Sign up</button>
or <a href="#" ng-click='scenario="Log in"'>Log in</a>
</form>
<form ng-show="scenario == 'Log in'">
<h2>Log in</h2>
Username: <input type="text" ng-model="user.username" /><br />
Password: <input type="password" ng-model="user.password" /><br />
<button ng-click="logIn(user)">Log in</button>
or <a href="#" ng-click='scenario="Sign up"'>Sign up</a>
</form>
</div>
<div ng-show="currentUser">
<h1>Welcome {{currentUser.get('username')}}</h1>
{{currentUser.get('Picture')}}
<p>{{currentUser.get('FirstName')}} {{currentUser.get('LastName')}}</p>
<p>{{currentUser.get('Status')}}</p>
<p>{{currentUser.get('DOB')}}</p>
<p>Expires: {{currentUser.get('Expiry')}}</p>
<button ng-click="logOut(user)">Log out</button>
</div>
</body>
</html>
Javascript:
Parse.initialize("x", "x");
angular.module('AuthApp', []).run(['$rootScope', function($scope) {
$scope.scenario = 'Sign up';
$scope.currentUser = Parse.User.current();
$scope.signUp = function(form) {
var fileUploadControl = $("#picture")[0];
if (fileUploadControl.files.length > 0) {
var file = fileUploadControl.files[0];
var name = file.name;
var parseFile = new Parse.File(name, file);
parseFile.save().then(function() {
}, function(error){
});
var user = new Parse.User();
user.set("Picture", parseFile);
user.set("email", form.email);
user.set("username", form.username);
user.set("password", form.password);
user.set("FirstName", form.firstName);
user.set("LastName", form.lastName);
user.set("Mobile", form.mobile);
user.set("DOB", form.dob);
user.set("Status", "New User");
user.save();
user.signUp(null, {
success: function(user) {
$scope.currentUser = user;
$scope.$apply();
},
error: function(user, error) {
alert("Unable to sign up: " + error.code + " " + error.message);
}
});
}
};
$scope.logIn = function(form) {
Parse.User.logIn(form.username, form.password, {
success: function(user) {
$scope.currentUser = user;
$scope.$apply();
},
error: function(user, error) {
alert("Unable to log in: " + error.code + " " + error.message);
}
});
};
$scope.logOut = function(form) {
Parse.User.logOut();
$scope.currentUser = null;
};
}]);
尝试移动保存用户的内容,使其位于 parseFile.save
后面的 then 语句中。我相信您需要在尝试使用它之前完成保存文件。
Parse.initialize("x", "x");
angular.module('AuthApp', []).run(['$rootScope', function($scope) {
$scope.scenario = 'Sign up';
$scope.currentUser = Parse.User.current();
$scope.signUp = function(form) {
var fileUploadControl = $("#picture")[0];
if (fileUploadControl.files.length > 0) {
var file = fileUploadControl.files[0];
var name = file.name;
var parseFile = new Parse.File(name, file);
parseFile.save().then(function() {
var user = new Parse.User();
user.set("Picture", parseFile);
user.set("email", form.email);
user.set("username", form.username);
user.set("password", form.password);
user.set("FirstName", form.firstName);
user.set("LastName", form.lastName);
user.set("Mobile", form.mobile);
user.set("DOB", form.dob);
user.set("Status", "New User");
user.save();
user.signUp(null, {
success: function(user) {
$scope.currentUser = user;
$scope.$apply();
},
error: function(user, error) {
alert("Unable to sign up: " + error.code + " " + error.message);
}
});
},
function(error) {
});
}
};
$scope.logIn = function(form) {
Parse.User.logIn(form.username, form.password, {
success: function(user) {
$scope.currentUser = user;
$scope.$apply();
},
error: function(user, error) {
alert("Unable to log in: " + error.code + " " + error.message);
}
});
};
$scope.logOut = function(form) {
Parse.User.logOut();
$scope.currentUser = null;
};
}]);
相关文章:
- 使用JSP从服务器检索和显示图像
- 通过Magento的网络服务检索运费
- 如何通过php页面将数据库值检索到jquery自动完成框中
- Parse.com 检索嵌套对象的值
- 如何使用Parse.Query检索特定对象
- Parse.com-在JavaScript SDK中模板化集合时检索图像URL
- 检索parse.com数据并在数据表中显示
- 如何使用javascript存储然后从Parse中检索图像
- Parse.com / Backbone.js如何使用JavaScript检索/列出其他用户的公共显示名称
- 从Javascript对象中的CSV检索解析后的数据(使用Papa Parse)
- 当我从数据库中检索值时,为什么Parse中的链式函数不起作用
- 通过REST从Parse.com检索Fullcalendar事件
- 无法使用从Parse.com检索的数据构造DataTable
- 如何从parse.com检索文件
- 在更新对象(_User)并稍后检索它之后,字段不会更新(Parse)
- 如何检索对象信息,并将其添加到一个数组Parse.com/Express JS
- 使用javascript从Parse.com检索图像
- 使用 Parse.com 中的指针检索数据
- 使用JSON.parse()检索本地存储数组列表
- 无法使用Parse.Query检索键值