我想在其列之一中添加包含图像的新对象,但它不保存我的照片,我的代码中是否有任何错误?特别是保存图像的一部分!!
出现问题的我的 JavaScript:
它从不在解析中上传我的照片!!
<script type="text/javascript">
Parse.initialize("key", "key");
var products = Parse.Object.extend("products");
var fileUploadControl = $("#profilePhotoFileUpload")[0];
if (fileUploadControl.files.length > 0) {
var file = fileUploadControl.files[0];
var name = "photo.png";
var parseFile = new Parse.File(name, file);
}
parseFile.save().then(function() {
//The file has been saved to Parse.
}, function(error) {
// The file either could not be read, or could not be saved to Parse.
});
</script>
这里我添加了 html 行来上传文件:
<input type="file" id="profilePhotoFileUpload">
最佳答案
我得到了答案,我正在与你分享,也许有人会受益
THML
上传文件的行是:
<input type="file" id="pic">
<script>
中的代码在解析中获取和保存图像是:
var fileUploadControl = $("#pic")[0];
if (fileUploadControl.files.length > 0) {
var file = fileUploadControl.files[0];
var name = "photo.png";
var parseFile = new Parse.File(name, file);
//put this inside if {
parseFile.save().then(function() {
// The file has been saved to Parse.
}, function(error) {
// The file either could not be read, or could not be saved to Parse.
});
// Be sure of ur parameters name
// prod is extend of my class in parse from this: var prod = new products();
prod.set("picture", parseFile);
prod.save();
}
关于javascript - 如何通过 JavaScript 在 Parse.com 中保存图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23463012/