gpt4 book ai didi

javascript - 如何使用 Parse.com JavaScript SDK 上传图像?

转载 作者:行者123 更新时间:2023-11-29 14:59:28 25 4
gpt4 key购买 nike

我正在使用 Parse.com 构建一个 JavaScript 应用程序,我需要上传照片。我有一个允许用户在他们的文件系统上选择图像的表单,但是接下来我该怎么做呢?我在 Parse 网站上找不到任何关于此的文档(无论如何不是针对 JavaScript SDK)。

最佳答案

这是一个关于如何上传图片的简单示例:

<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script type="text/javascript" src="http://www.parsecdn.com/js/parse-1.2.15.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {

// ***************************************************
// NOTE: Replace the following your own keys
// ***************************************************

Parse.initialize("YOUR_APPLICATION_ID", "YOUR_CLIENT_ID");

function saveJobApp(objParseFile)
{
var jobApplication = new Parse.Object("JobApplication");
jobApplication.set("applicantName", "Joe Smith");
jobApplication.set("profileImg", objParseFile);
jobApplication.save(null,
{
success: function(gameScore) {
// Execute any logic that should take place after the object is saved.
var photo = gameScore.get("profileImg");
$("#profileImg")[0].src = photo.url();
},
error: function(gameScore, error) {
// Execute any logic that should take place if the save fails.
// error is a Parse.Error with an error code and description.
alert('Failed to create new object, with error code: ' + error.description);
}
});
}

$('#profilePhotoFileUpload').bind("change", function(e) {
var fileUploadControl = $("#profilePhotoFileUpload")[0];
var file = fileUploadControl.files[0];
var name = file.name; //This does *NOT* need to be a unique name
var parseFile = new Parse.File(name, file);

parseFile.save().then
(
function()
{
saveJobApp(parseFile);
},
function(error)
{
alert("error");
}
);
});

});
</script>

<body>
<input type="file" id="profilePhotoFileUpload">
<img id="profileImg"/>
</body>

关于javascript - 如何使用 Parse.com JavaScript SDK 上传图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12279515/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com