Fix photo upload from wikidata.
authorRadek Czajka <rczajka@rczajka.pl>
Thu, 24 Nov 2022 10:51:13 +0000 (11:51 +0100)
committerRadek Czajka <rczajka@rczajka.pl>
Thu, 24 Nov 2022 10:51:13 +0000 (11:51 +0100)
src/catalogue/static/catalogue/wikidata_admin.js

index d2af5f7..a9af9c9 100644 (file)
 
         function set_file_from_url($input, url, callback) {
             filename = decodeURIComponent(url.match(/.*\/(.*)/)[1]);
 
         function set_file_from_url($input, url, callback) {
             filename = decodeURIComponent(url.match(/.*\/(.*)/)[1]);
-            $.ajax({
-                url: url,
-                success: function(content) {
-                    let file = new File([content], filename);
-                    let container = new DataTransfer(); 
-                    container.items.add(file);
-                    $input[0].files = container.files;
-                    callback()
-                }
-            });
+
+            let req = new XMLHttpRequest();
+            req.open("GET", url, true);
+            req.responseType = "arraybuffer";
+            req.onload = (event) => {
+                let file = new File([req.response], filename);
+                let container = new DataTransfer(); 
+                container.items.add(file);
+                $input[0].files = container.files;
+                callback();
+            };
+            req.send(null);
         }
     });
 })(jQuery);
         }
     });
 })(jQuery);