Skip to content

Instantly share code, notes, and snippets.

@scytacki
Last active August 29, 2015 14:15
Show Gist options
  • Save scytacki/aa7f557a11080cafe01d to your computer and use it in GitHub Desktop.
Save scytacki/aa7f557a11080cafe01d to your computer and use it in GitHub Desktop.
function uploadImage() {
// Make the URL links.
var API_URL = server + '/api/v1/media_objects';
var form = document.getElementById('file-form');
var fileSelect = document.getElementById('file-select');
// Get the selected files from the input.
var files = fileSelect.files;
// Create a new FormData object.
var formData = new FormData();
// check the first file
var file = files[0];
// Check the file type.
if (!file.type.match('image.*')) {
alert("only supports image files");
return;
}
// Add the file to the request.
formData.append('upload', file, file.name);
formData.append('email', '[email protected]');
formData.append('password', '[filtered]');
formData.append('type', 'data_set');
formData.append('id', datasetID);
// Post to iSENSE
var xhr = new XMLHttpRequest();
xhr.open('POST', API_URL, true);
xhr.send(formData);
xhr.onloadend = function () {
console.log("finished iSense post");
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment