Fix drag upload bug.

This commit is contained in:
BoHung Chiu 2021-09-23 11:35:44 +08:00
parent d401049a92
commit 3ad002bdf1
2 changed files with 21 additions and 6 deletions

View File

@ -82,6 +82,17 @@ class Admin::ArchiveFilesController < OrbitAdminController
render :partial => "categories_order" if request.xhr?
end
def create
params["archive_file"]["archive_file_multiples_attributes"].each do |k,v|
if v["file"].class == String
file_content_info = JSON.parse(v["file"])
content_type = file_content_info["type"]
filename = file_content_info["name"]
head = "Content-Disposition: form-data; name=\"archive_file[archive_file_multiples_attributes][#{k}][file]\"; filename=\"#{filename}\" Content-Type: #{content_type}"
tempfile = Tempfile.new(filename,binmode: true)
tempfile.write(file_content_info["content"].unpack('U*').map{|i| i.chr }.join)
v["file"] = ActionDispatch::Http::UploadedFile.new({:filename=>filename,:type=>content_type,:head=>head,:tempfile=>tempfile})
end
end rescue nil
@archive_file = ArchiveFile.new(archive_vars)
@archive_file.create_user_id = current_user.id
@archive_file.update_user_id = current_user.id

View File

@ -249,13 +249,17 @@
}
function FileListItems (files) {
var b;
if(window.dataTransfer){
b = window.dataTransfer;
}else{
if(typeof(ClipboardEvent) == "undefined"){ //IE
b = new DataTransfer();
try{
b = new DataTransfer();
}catch(e){
if(window.dataTransfer){
b = window.dataTransfer;
}else{
b = new ClipboardEvent("").clipboardData;
if(typeof(ClipboardEvent) == "undefined"){ //IE
b = new DataTransfer();
}else{
b = new ClipboardEvent("").clipboardData;
}
}
}
if(b.items){