HDFS-7767. Use the noredirect flag in WebHDFS to allow web browsers to upload files via the NN UI (Ravi Prakash via aw)

This commit is contained in:
Allen Wittenauer 2016-06-03 17:07:39 -07:00
parent 15f018434c
commit 99a771cd7a
2 changed files with 74 additions and 2 deletions

View File

@ -119,6 +119,23 @@ <h4 class="modal-title">Create Directory</h4>
</div> </div>
</div> </div>
<div class="modal" id="modal-upload-file" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header"><button type="button" class="close"
data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title" id="file-upload-title">Upload File</h4>
</div>
<div class="modal-body" id="file-upload-body">
<input id="modal-upload-file-input" type="file" class="file" multiple>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-success" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-success" id="modal-upload-file-button" data-complete-text="Uploading...">Upload</button>
</div>
</div>
</div>
</div>
<div class="modal" id="delete-modal" tabindex="-1" role="dialog" aria-hidden="true"> <div class="modal" id="delete-modal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog"> <div class="modal-dialog">
<div class="modal-content"> <div class="modal-content">
@ -142,7 +159,7 @@ <h4 class="modal-title" id="delete-modal-title">Delete</h4>
</div> </div>
<div class="row"> <div class="row">
<div class="col-xs-11"> <div class="col-xs-10 col-md-10">
<form onsubmit="return false;"> <form onsubmit="return false;">
<div class="input-group"> <div class="input-group">
<input type="text" class="form-control" id="directory"/> <input type="text" class="form-control" id="directory"/>
@ -152,12 +169,16 @@ <h4 class="modal-title" id="delete-modal-title">Delete</h4>
</div> </div>
</form> </form>
</div> </div>
<div class="col-xs-1"> <div class="col-xs-2 col-md-2">
<button type="button" class="btn btn-default" data-toggle="modal" <button type="button" class="btn btn-default" data-toggle="modal"
aria-label="New Directory" data-target="#btn-create-directory" aria-label="New Directory" data-target="#btn-create-directory"
title="Create Directory"> title="Create Directory">
<span class="glyphicon glyphicon-folder-open"></span> <span class="glyphicon glyphicon-folder-open"></span>
</button> </button>
<button type="button" class="btn btn-default" data-toggle="modal"
data-target="#modal-upload-file" title="Upload Files">
<span class="glyphicon glyphicon-cloud-upload"></span>
</button>
</div> </div>
</div> </div>

View File

@ -366,5 +366,56 @@
}); });
}) })
$('#modal-upload-file-button').click(function() {
$(this).prop('disabled', true);
$(this).button('complete');
var files = []
var numCompleted = 0
for(var i = 0; i < $('#modal-upload-file-input').prop('files').length; i++) {
(function() {
var file = $('#modal-upload-file-input').prop('files')[i];
var url = '/webhdfs/v1' + current_directory;
url = encode_path(append_path(url, file.name));
url += '?op=CREATE&noredirect=true';
files.push( { file: file } )
files[i].request = $.ajax({
type: 'PUT',
url: url,
processData: false,
crossDomain: true
});
})()
}
for(var f in files) {
(function() {
var file = files[f];
file.request.done(function(data) {
var url = data['Location'];
$.ajax({
type: 'PUT',
url: url,
data: file.file,
processData: false,
crossDomain: true
}).complete(function(data) {
numCompleted++;
if(numCompleted == files.length) {
$('#modal-upload-file').modal('hide');
$('#modal-upload-file-button').button('reset');
browse_directory(current_directory);
}
}).error(function(jqXHR, textStatus, errorThrown) {
numCompleted++;
show_err_msg("Couldn't upload the file " + file.file.name + ". "+ errorThrown);
});
}).error(function(jqXHR, textStatus, errorThrown) {
numCompleted++;
show_err_msg("Couldn't find datanode to write file. " + errorThrown);
});
})();
}
});
init(); init();
})(); })();