add a dialog for large file size warning + simplify chunking logic

pull/2162/head
Kaushik Chaubal 9 years ago committed by Bin Han
parent 7d4965abc0
commit 7cd59275ea

@ -23,13 +23,10 @@ class LargeFileManager(FileContentsManager):
os_path = self._get_os_path(path)
# First chunk
if chunk == 1:
self.log.debug("Saving %s", os_path)
self.run_pre_save_hook(model=model, path=path)
try:
# First chunk
if chunk == 1:
self.log.debug("Saving %s", os_path)
self.run_pre_save_hook(model=model, path=path)
super(LargeFileManager, self)._save_file(os_path, model['content'], model.get('format'))
else:
self._save_large_file(os_path, model['content'], model.get('format'))

@ -278,27 +278,38 @@ define([
var name_and_ext = utils.splitext(f.name);
var file_ext = name_and_ext[1];
// replace the error message to the new upload function
if (f.size > this._max_upload_size_mb * 1024 * 1024) {
that.add_large_file_upload_button(f);
continue;
dialog.modal({
title : 'Large file size warning',
body : "The file size is " + Math.round(f.size / (1024 * 1024)) + "MB. Do you still want to upload it?",
buttons : {
Cancel: {},
Ok: {
class: "btn-primary",
click: function() {
that.add_large_file_upload_button(f);
}
}
}
});
}
var reader = new FileReader();
if (file_ext === '.ipynb') {
reader.readAsText(f);
} else {
// read non-notebook files as binary
reader.readAsArrayBuffer(f);
else{
var reader = new FileReader();
if (file_ext === '.ipynb') {
reader.readAsText(f);
} else {
// read non-notebook files as binary
reader.readAsArrayBuffer(f);
}
var item = that.new_item(0, true);
item.addClass('new-file');
that.add_name_input(f.name, item, file_ext === '.ipynb' ? 'notebook' : 'file');
// Store the list item in the reader so we can use it later
// to know which item it belongs to.
$(reader).data('item', item);
reader.onload = reader_onload;
reader.onerror = reader_onerror;
}
var item = that.new_item(0, true);
item.addClass('new-file');
that.add_name_input(f.name, item, file_ext === '.ipynb' ? 'notebook' : 'file');
// Store the list item in the reader so we can use it later
// to know which item it belongs to.
$(reader).data('item', item);
reader.onload = reader_onload;
reader.onerror = reader_onerror;
}
// Replace the file input form wth a clone of itself. This is required to
// reset the form. Otherwise, if you upload a file, delete it and try to
@ -1209,9 +1220,7 @@ define([
model.chunk = chunk;
model.content = filedata;
// TODO(yuazhang): Why refresh filedata?
filedata = item.data('filedata');
var on_success = function (event) {
if (offset < f.size) {
// of to the next chunk

Loading…
Cancel
Save