如何从表单中获取文件并将其保存到 Parse? 我尝试了几十种变体:
<form id="image_form" enctype="multipart/form-data" action="/upload/image" method="post">
<h3>Upload icon image: </h3>
<p><input id="image_file" name="image_file" type="file"></p>
<p><input id="event_submit" type="submit" value="Create" onclick="makeEventSnip();"></p>
</form>
在 JavaScript 中:
function makeEventSnip() {
event.preventDefault();
var fileUploadControl = document.getElementById('image_file');
var file = fileUploadControl.files[0];
var name = "icon.png";
var iconImageFile = new Parse.File(name, file);
alert(iconImageFile.getUrl());
我尝试按照 Parse 的 JS 指南 ( https://parse.com/docs/js/guide ) 中所说的方式进行操作,但这也不起作用。它似乎没有从表单中获取任何内容。我错过了什么?
最佳答案
试试这个
var fileUploadControl = document.getElementById('image_file');
var file = fileUploadControl.files[0];
var name = "icon.png";
var iconImageFile = new Parse.File(name, file);
iconImageFile.save().then(function() {//you need to call after save the file
alert(iconImageFile._url);
}
关于javascript - 使用 Javascript 上传 Parse.File,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32526349/