1
votes

when uploading a pdf get error: Uncaught TypeError: Cannot read property '0' of null

my config js:

 $(function(){
  var csrf_token = $('meta[name=csrf-token]').attr('content');
  var csrf_param = $('meta[name=csrf-param]').attr('content');
  var params;
  if (csrf_param !== undefined && csrf_token !== undefined) {
   params = csrf_param + "=" + encodeURIComponent(csrf_token);
  } 
  $('.redactor').redactor(
   { "imageUpload":"/redactor_rails/pictures?" + params,
     "fileUpload":"/redactor_rails/documents?" + params,
     "imageGetJson":"/redactor_rails/pictures",
     "path":"/assets/redactor-rails",
     "css":"style.css"}
  );

});

RedactorRailsDocumentUploader:

  class RedactorRailsDocumentUploader < CarrierWave::Uploader::Base
   include RedactorRails::Backend::CarrierWave

   # storage :fog
   storage :file

   def store_dir
    "system/redactor_assets/documents/#{model.id}"
   end

   def extension_white_list
     RedactorRails.document_file_types
   end
  end
1

1 Answers

0
votes

I suspect it's because you don't have file type 'PDF' listed in your RedactorRails.document_file_types.

In the redactor-rails gem it lists only 'pdf', not 'PDF', 'Pdf' etc. See line 23 here: https://github.com/SammyLin/redactor-rails/blob/master/lib/redactor-rails.rb

Unless you have a security need for this I would comment out:

   def extension_white_list
     RedactorRails.document_file_types
   end