[fix] if no_socketio specified, upload file with FileReader
This commit is contained in:
parent
9439a808a1
commit
884555b645
3 changed files with 25 additions and 9 deletions
|
|
@ -612,6 +612,9 @@ select.form-control {
|
|||
font-weight: 500;
|
||||
color: #8D99A6;
|
||||
}
|
||||
.attach-btn {
|
||||
margin-top: 10px;
|
||||
}
|
||||
@media (min-width: 768px) {
|
||||
.layout-main .form-column.col-sm-12 > form > .input-max-width {
|
||||
max-width: 50%;
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ frappe.upload = {
|
|||
|
||||
|
||||
if(!opts.btn) {
|
||||
opts.btn = $('<button class="btn btn-default btn-sm">' + __("Attach")
|
||||
opts.btn = $('<button class="btn btn-default btn-sm attach-btn">' + __("Attach")
|
||||
+ '</div>').appendTo($upload);
|
||||
} else {
|
||||
$(opts.btn).unbind("click");
|
||||
|
|
@ -280,20 +280,29 @@ frappe.upload = {
|
|||
|
||||
let start_complete = frappe.cur_progress ? frappe.cur_progress.percent : 0;
|
||||
|
||||
var upload_with_filedata = function() {
|
||||
let freader = new FileReader();
|
||||
freader.onload = function() {
|
||||
var dataurl = freader.result;
|
||||
args.filedata = freader.result.split(",")[1];
|
||||
args.file_size = fileobj.size;
|
||||
frappe.upload._upload_file(fileobj, args, opts, dataurl);
|
||||
};
|
||||
freader.readAsDataURL(fileobj);
|
||||
}
|
||||
|
||||
if (opts.no_socketio) {
|
||||
upload_with_filedata();
|
||||
return;
|
||||
}
|
||||
|
||||
frappe.socketio.uploader.start({
|
||||
file: fileobj,
|
||||
filename: args.filename,
|
||||
is_private: args.is_private,
|
||||
fallback: () => {
|
||||
// if fails, use old filereader
|
||||
let freader = new FileReader();
|
||||
freader.onload = function() {
|
||||
var dataurl = freader.result;
|
||||
args.filedata = freader.result.split(",")[1];
|
||||
args.file_size = fileobj.size;
|
||||
frappe.upload._upload_file(fileobj, args, opts, dataurl);
|
||||
};
|
||||
freader.readAsDataURL(fileobj);
|
||||
upload_with_filedata();
|
||||
},
|
||||
callback: (data) => {
|
||||
args.file_url = data.file_url;
|
||||
|
|
|
|||
|
|
@ -762,6 +762,10 @@ select.form-control {
|
|||
color: @text-muted;
|
||||
}
|
||||
|
||||
.attach-btn {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
// above mobile
|
||||
@media (min-width: 768px) {
|
||||
.layout-main .form-column.col-sm-12 > form > .input-max-width {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue