Created
February 4, 2016 08:35
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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