]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/attachment.pm
let thru HTTP_ACCEPT
[git.ikiwiki.info.git] / IkiWiki / Plugin / attachment.pm
index 6004a09828721af15032f7e3396e40d99141aee0..4af9ac92bc2caf5b0c52002d83602dc46d1657ad 100644 (file)
@@ -252,22 +252,25 @@ sub attachment_store {
                        IkiWiki::fast_file_copy($tempfile, $filename, $fh, @_);
                });
        }
-       
+
        # Return JSON response for the jquery file upload widget.
-       eval q{use JSON};
-       error $@ if $@;
-       print "Content-type: application/json\n\n";
-       my $size=-s $dest."/".$filename;
-       print to_json([
-               {
-                       name => $filename,
-                       size => $size,
-                       humansize => IkiWiki::Plugin::filecheck::humansize($size),
-                       stored_msg => stored_msg(),
-                       
-               }
-       ]);
-       exit 0;
+       if ($q->Accept("application/json") >= 1.0 &&
+           grep { /application\/json/i } $q->Accept) {
+               eval q{use JSON};
+               error $@ if $@;
+               print "Content-type: application/json\n\n";
+               my $size=-s $dest."/".$filename;
+               print to_json([
+                       {
+                               name => $filename,
+                               size => $size,
+                               humansize => IkiWiki::Plugin::filecheck::humansize($size),
+                               stored_msg => stored_msg(),
+                               
+                       }
+               ]);
+               exit 0;
+       }
 }
 
 # Save all stored attachments for a page.