Skip to content

Instantly share code, notes, and snippets.

@phynet
Created February 4, 2016 08:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phynet/1341c0b85a5e2150e485 to your computer and use it in GitHub Desktop.
Save phynet/1341c0b85a5e2150e485 to your computer and use it in GitHub Desktop.
This was a JS - HTML that I found in the interwebs and changed it to fit my needs, when Parse was alive did work. RIP.
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<form id='fileupload' name='fileupload' enctype='multipart/form-data' method='post'>
<fieldset>
<input type='file' name='fileselect' id='fileselect'></input>
<input id='uploadbutton' type='button' value='Upload to Parse'/></br></br>
File URL <input type='text' id='resultURL' size='155'></input>
</fieldset>
</form>
<script type='text/javascript'>
$(function() {
var file;
// Set an event listener on the Choose File field.
$('#fileselect').bind('change', function(e) {
var files = e.target.files || e.dataTransfer.files;
// Our file var now holds the selected file
file = files[0];
});
// This function is called when the user clicks on Upload to Parse. It will create the REST API request to upload this image to Parse.
$('#uploadbutton').click(function() {
var serverUrl = 'https://api.parse.com/1/files/' + file.name;
$.ajax({
type: 'POST',
beforeSend: function(request) {
request.setRequestHeader('X-Parse-Application-Id', 'YOURAPPID');
request.setRequestHeader('X-Parse-REST-API-Key', 'YOURAPPKEY');
request.setRequestHeader('Content-Type', file.type);
},
url: serverUrl,
data: file,
processData: false,
contentType: false,
success: function(data) {
if (window.confirm('File available at: ' + data.url)){
window.open(data.url);
}else{
document.getElementById('resultURL').value = data.url;
}
document.getElementById('resultURL').value = data.url;
},
error: function(data) {
var obj = jQuery.parseJSON(data);
alert(obj.error);
window.alert('ERROR');
}
});
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment