One of the challenges I am facing is setting up a signup form where users can upload their images.
I encountered an issue while trying to upload to parse.com. When running the following JavaScript code, I received an alert with code 100. It's worth noting that there are no connection problems with parse.com, as regular signups work fine.
var fileUploadControl = $("#img1")[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.
var url = parseFile.url();
user.set("img", url);
}, function(error) {
alert("Error: " + error.code + " " + error.message);
// The file either could not be read, or could not be saved to Parse.
});
}
Here is the HTML markup where "img1" is declared:
<form dir="rtl" class="form-container" id="signUp_form" method='post'>
.........................
......................
<input type="file" name="img1" size="40" id="img1" onchange="readURL(this);">
<img id="blah" src="empty-f.gif" alt="your image" width="150px" height="150px" />
</form>
If necessary, here is the relevant function:
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#blah')
.attr('src', e.target.result);
};
reader.readAsDataURL(input.files[0]);
}
}
Thank you!