Export then Import of Resources gives Error: File type is not allowed.

6 posts / 0 new
Last post
jslauson
Export then Import of Resources gives Error: File type is not allowed.

I have two instances of CWIS 3.2.0 with identical configurations, metadata fields, etc. However, when I use "Export Resources" on one and then try to import it on the other with "Import Tab-Delimited Data", I get "Error: File type is not allowed." no matter what I do. I've done this a number of times before, so I'm pretty sure that I know what I'm doing, but I'm stumped as to why it isn't working this time. I've scrubbed the data of errant tabs and line-feeds, I even replaced the Release Flag values with 1 and 0 like the documentation says, instead of the exported TRUE and FALSE.

On an unrelated note, the CWIS Forums on this site are also displaying the error "Notice: Undefined index: path in menu_token_entity_context->object_load() (line 24 of /var/www/scout.wisc.edu/html/sites/all/modules/menu_token/plugins/menu_token_entity_context.inc)." on every page.

chalpin
Re: Export then Import of Resources gives Error: File type is...

When your browser saved the exported data, what file extension did it use? If your data file were saved with a .php extension, rather than .txt or .tsv, then that could cause the error you are seeing.

As for the notice on the Forums -- this is a known bug in one of the Drupal modules we're using for the Forums site. We're waiting for a fix from the module author.

jslauson
Re: Export then Import of Resources gives Error: File type is...

Thanks for your reply. It exported it as a tsv file. I tried both tsv and txt extensions, both with no joy. While awaiting reply, I tried truncating the file to just the header line and a single record (so about 5 or 6 lines total). That imported successfully, so I'm going to use binary division to see if I can isolate precisely where in the file CWIS is having a problem with it. I ticked the "Debug" checkmark on the Import Data form, but is there a debug flag in the PHP that I can set to have it spit more output at me?

jslauson
Re: Export then Import of Resources gives Error: File type is...

After 18 divisions, the answer is:

If a Resource has a Description field with an <a href> tag in it then the TSV file fails to import with "Error: File type is not allowed.", EVEN IF "Allow HTML in Text:" is set to "Yes" for the Description Paragraph field in the Metadata Field Editor. Other various inline HTML seems to be fine, however.

Interestingly, one of the problematic records with an anchor tag in the description was a Sample Record originally supplied with CWIS from way back when. The current SampleRecords.xml file from CWIS 3.2.0 doesn't appear to contain any such records though.

chalpin
Re: Export then Import of Resources gives Error: File type is...

That doesn't make sense given the code in ImportDataExecute -- "Error: File type is not allowed" occurs in only two places. On line 514, where the file extension is checked, and on line 558 where the mime type of the uploaded file is checked. Both of those places occur before any validation of content whatsoever has taken place, so it's not clear to me how the "<a href>" could factor in.

I suppose it's possible that the <a href> is confusing PHP's mime_content_type() funcion? This might be PHP-version dependent -- what version of PHP are you on? I've tried a variety of exported files from our own internal CWIS sites, including several that include <a href> tags and even one from a stock install of CWIS 3.0.0 with the old sample records, and none of them have confused mime_content_type() in PHP 5.3.3 -- they're all properly detected as text/plain.

jslauson
Re: Export then Import of Resources gives Error: File type is...

It is definitely an issue with PHP function mime_content_type() being thrown off. I downloaded a fresh TSV file CWIS and ran the UNIX `file` command and PHP's mime_content_type() against it on a sample of four different server configs, the results are copypasted below. Summary: PHP 5.3 to 5.6 all recognize it as text/html. Fedora-descended Linux's `file` reports extended-ASCII (it's exporting from a ISO-8859-1/Windows-Latin-1 server), but the Mac's BSD-based `file` sees it as HTML. If I simply delete the < in front of the "a href", then all PHPs reports "text/plain".

Problem identified, I have a manageable work-around, and I hope this also helps you and others.

RHEL Server 6.7, PHP 5.6.17
> file ResourceExport-0097-160126-121958.tsv
Non-ISO extended-ASCII English text, with very long lines
> php -r 'echo mime_content_type("ResourceExport-0097-160126-121958.tsv")."\n";'
text/html

CentOS 6.5, PHP 5.3.28
> file ResourceExport-0097-160126-121958.tsv
Non-ISO extended-ASCII English text, with very long lines
> php -r 'echo mime_content_type("ResourceExport-0097-160126-121958.tsv")."\n";'
text/html

CentOS 6.7, PHP 5.6.17
> file ResourceExport-0097-160126-121958.tsv
Non-ISO extended-ASCII English text, with very long lines
> php -r 'echo mime_content_type("ResourceExport-0097-160126-121958.tsv")."\n";'
text/html

Mac OS X 10.11.3, PHP 5.5.30
> file ResourceExport-0097-160126-121958.tsv
HTML document text
> php -r 'echo mime_content_type("ResourceExport-0097-160126-121958.tsv")."\n";'
text/html