Skip to content

Instantly share code, notes, and snippets.

@alpocr
Created November 26, 2014 21:24
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save alpocr/f26a4e6c3683ccda2daf to your computer and use it in GitHub Desktop.
<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="filename" id="filename"></input>
<input id="uploadbutton" type="button" value="Upload to GCS"/>
</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://mall4g-backend.appspot.com/_ah/api/mall4g/v1.0/files/insert';
$.ajax({
type: "POST",
beforeSend: function(request) {
request.setRequestHeader("Content-Type", file.type);
},
url: serverUrl,
data: file,
processData: false,
contentType: false,
success: function(data) {
alert("File available at: " + data.url);
},
error: function(data) {
var obj = jQuery.parseJSON(data);
alert(obj.error);
}
});
});
});
</script>
Thank you - it seems to be working now. I had used that link originally, and I'm not really sure what I changed that made it work, but it seem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment