From fa8ae228bf7450dafb1f03d78c2845ffb3fd4dc4 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Tue, 11 Jun 2013 13:38:01 -0400 Subject: [PATCH 1/3] Seems like on chrome when cancel is hit in the file chooser, the 'changed' event is fired and startUpload() was being called. We need to check to see if the upload file is blank and - if so - just return immediately out of the function --- cms/djangoapps/contentstore/views/assets.py | 3 +++ cms/static/js/base.js | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cms/djangoapps/contentstore/views/assets.py b/cms/djangoapps/contentstore/views/assets.py index b5041d3e9f..872b71bcb7 100644 --- a/cms/djangoapps/contentstore/views/assets.py +++ b/cms/djangoapps/contentstore/views/assets.py @@ -103,6 +103,9 @@ def upload_asset(request, org, course, coursename): logging.error('Could not find course' + location) return HttpResponseBadRequest() + if 'file' not in request.FILES: + return HttpResponseBadRequest() + # compute a 'filename' which is similar to the location formatting, we're using the 'filename' # nomenclature since we're using a FileSystem paradigm here. We're just imposing # the Location string formatting expectations to keep things a bit more consistent diff --git a/cms/static/js/base.js b/cms/static/js/base.js index fe60d80239..2260579e49 100644 --- a/cms/static/js/base.js +++ b/cms/static/js/base.js @@ -411,8 +411,12 @@ function showFileSelectionMenu(e) { } function startUpload(e) { + file_input = $('.file-input').val().replace('C:\\fakepath\\', ''); + if (file_input === '') + return; + $('.upload-modal h1').html(gettext('Uploading…')); - $('.upload-modal .file-name').html($('.file-input').val().replace('C:\\fakepath\\', '')); + $('.upload-modal .file-name').html(file_input); $('.upload-modal .file-chooser').ajaxSubmit({ beforeSend: resetUploadBar, uploadProgress: showUploadFeedback, From 1602f592b4b22ec79cad85baa9e7f831048b77a9 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Tue, 11 Jun 2013 14:32:33 -0400 Subject: [PATCH 2/3] use better API --- cms/static/js/base.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cms/static/js/base.js b/cms/static/js/base.js index 2260579e49..c07cb53ccf 100644 --- a/cms/static/js/base.js +++ b/cms/static/js/base.js @@ -411,12 +411,12 @@ function showFileSelectionMenu(e) { } function startUpload(e) { - file_input = $('.file-input').val().replace('C:\\fakepath\\', ''); - if (file_input === '') + files = $('.file-input').get(0).files; + if (files.length === 0) return; $('.upload-modal h1').html(gettext('Uploading…')); - $('.upload-modal .file-name').html(file_input); + $('.upload-modal .file-name').html(files[0].name); $('.upload-modal .file-chooser').ajaxSubmit({ beforeSend: resetUploadBar, uploadProgress: showUploadFeedback, From be6fbf913e779e7f7ba093492e8d1196314957b8 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Tue, 11 Jun 2013 14:36:04 -0400 Subject: [PATCH 3/3] make local variable --- cms/static/js/base.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cms/static/js/base.js b/cms/static/js/base.js index c07cb53ccf..c626fa1b3f 100644 --- a/cms/static/js/base.js +++ b/cms/static/js/base.js @@ -411,7 +411,7 @@ function showFileSelectionMenu(e) { } function startUpload(e) { - files = $('.file-input').get(0).files; + var files = $('.file-input').get(0).files; if (files.length === 0) return;