PDF Corrupted & Not Found After Migration

Re: PDF Corrupted & Not Found After Migration

by Ken Task -
Number of replies: 8
Picture of Particularly helpful Moodlers

First screen shot looks like a browser doesn't know what to do with a .pdf file it's supposed to be downloading - not displaying.  One can see in the header of that file a "PDF 1.4" designation.

What browser?  And have you checked browser settings for what to do with a PDF file?  Unless you have Adobe, typically Mac browsers will default to opening PDF's in Preview.

The second, might be related to unoconv ... a feature introduced in 3.1.   In setting of the Moodle, do you have /usr/bin/unoconv in the path box for unoconv?   Try removing that path and save.

Then go back to an assignment submission and attempt grading again.

You might have to turn on debugging for a bit to see if Moodle will give any more information on the second.

Was the moodledata directory transferred in a binary mode or an ascii mode?

You say all the  PDF's are corrupted?  Or just the ones you've checked out?
Might have to query the DB using the "humanly recognizable" name of a file
to find it's contenthash value and then manually copy out of moodledata/filedir/
a file that you think is corrupted.

The example provide shows it was a PDF in an assignment submission and
the humanly recognizable name was "Hasher Alam Task.pdf"

Here's the query to find that file's reference in the DB:

select contenthash from `mdl_files` where (`component` like "%assignsubmission%" and `filename` like "%Hasher Alam Task.pdf%")

Should show the contenthash ... i.e. location of the file.
something like:
25b7f1f30b49ae98e313e12885e4e8f5b8859549

then navigate /moodledata/filedir/25/b7/ to see if there is a file by
the contenthash name.

Copy that file in filedir out to your web root ... on CentOS web root is /var/www/html/ typically.

From moodledata in a shell for example:
cp ./filedir/25/b7/25b7f1f30b49ae98e313e12885e4e8f5b8859549 /var/www/html/test.pdf

Then use browser going directly to:
http://site/test.pdf
How does your browser behave?   Should prompt to download or launch with either Adobe or Preview, I would think.

Don't forget to remove the test.pdf file after testing.

'spirit of sharing', Ken

Average of ratings: Useful (1)
In reply to Ken Task

Ang: Re: PDF Corrupted & Not Found After Migration

by Lars Lyngsøe Højberg -

Hi Ken


I am having the exact same problem on my moodle installation. When I try displaying pdf-files (after a migration) they are corrupt - just as explained in the first post. When copying to the root folder and then accessing the file test.pdf all looks good.

What can I do to make Moodle serve files correctly?

Thank You.

/Lars

In reply to Lars Lyngsøe Højberg

Re: Ang: Re: PDF Corrupted & Not Found After Migration

by Ken Task -
Picture of Particularly helpful Moodlers

@Lars

We never heard back from @Naomi if what I had suggested worked or not.   The only thing in common - and remember just going on information provided here ... without specifics .... issue after a migration.

When I see the term 'migration' it means a site move .... from one location to another.   Locations could be localhost -> server (provider) or one provider to another provider .... as an example.  That could be accomplished in a variety of ways .... but the 'best' way is to transfer files server to server and use a tool  to transfer files that doesn't involve asciii mode (like FTP) - but does transfers binary.

This to say, some files could be corrupted if transferred by downloading only to turn around and upload (FTP ascii mode).  That's two transfers ... down then up.   Twice the chance for corruption on transfer.

But then again, is the new server setup exactly like the old?   Some folks have reported they simply can not use Moodle's Annotation which involves unoconv and libreoffice in a headless mode on their system.

Unlike other 'helpers' (du/ghostscript) that could be used by Moodle but the Moodle Admin user had to enter a path, the path to unoconv was populated in advance.   But, if new server didn't have it available + one could not install it for some reason, then that path should be removed.

Bottom line ... I really don't know .... this is a guess.

'spirit of sharing', Ken

In reply to Ken Task

Ang: Re: Ang: Re: PDF Corrupted & Not Found After Migration

by Lars Lyngsøe Højberg -

Hi Ken


Exactly - like searching for a needle in a haystack!

The rare thing is that new files of whatever kind are functioning perfectly - and files from before the migration doesn't. When I copy a file from the moodledata/filedir/etc to the webroot (http://www.mydomain.com/test.php) my browser serves the file as it should - but when viewed through moodle it wrecks up pdf's and png's (which are the filetypes I have tested).


I hope to find a solution instead of plowing through the heap of files :O)


Thank You - Lars

In reply to Lars Lyngsøe Højberg

Re: Ang: Re: Ang: Re: PDF Corrupted & Not Found After Migration

by Ken Task -
Picture of Particularly helpful Moodlers

Well, then ... is this linux?

Are there any additional software running that wasn't present on old?   suphp or SELinux etc.

What are ownerships/permissions on moodledata - recursively?   If in a secure location and not running suphp or things like SELinux wiithout a rule to handle non-apache known location one could be quite liberal with permissions.

Do you any filters turned on?

What about third party plugins/addons?

Is theme a custom theme or one that comes as 'standard'?

If linux, install moosh .... it's command line only ... but it does have some commands that work with filedir.

https://moosh-online.com/

https://moosh-online.com/commands/

commands like chkdatadir, data-stats, file-datacheck, file-dbcheck ... etc.

'spirit of sharing', Ken


In reply to Ken Task

Ang: Re: Ang: Re: Ang: Re: PDF Corrupted & Not Found After Migration

by Lars Lyngsøe Højberg -

Hi Ken

Thank You for your inspiring help!

I have tested a lot of things and the only thing I have found out is that if I compare two supposedly identical files - one downloaded via ftp which is OK and one downloaded through Moodle which is broken, the one through Moodle lacks som signs (^M). I used vimdiff to compare the files.

Does this tell You anything.

About SELinux I'm on a hosted server and Modsecurity is disabled.

Permissions are: folders 0755 and files 0665

Thank's again.

/Lars

In reply to Lars Lyngsøe Højberg

Re: Ang: Re: Ang: Re: Ang: Re: PDF Corrupted & Not Found After Migration

by Ken Task -
Picture of Particularly helpful Moodlers

???? ... uhh, am running out of ideas. :\    Never used vimdiff before ...

However, on the server itself, when you extract/save out a hashnamed file to another location do it twice ... once by it's hashname and one giving a 'normal' filename.ext - like 'some.pdf'.

Then do 'file -b some.pdf' and 'file -b contenthashnamenoextension'

Can you install 'moosh'?

https://moosh-online.com/

It is command line only and has some commands related to files.

https://moosh-online.com/commands/

Once installed, have to run commands from the moodle code directory.

Example:

cd /var/www/html/moodle/

moosh -n file-datacheck

(the -n is to run moosh as root)

Do you have any filters turned on?

'spirit of sharing', Ken


In reply to Ken Task

Ang: Re: Ang: Re: Ang: Re: Ang: Re: PDF Corrupted & Not Found After Migration

by Lars Lyngsøe Højberg -

Hi Ken

I actually ended up regenerating content from scratch - but thank you for your good advice. Keep up your good work and enthutiasm!


/Lars


In reply to Lars Lyngsøe Højberg

Re: Ang: Re: Ang: Re: Ang: Re: Ang: Re: PDF Corrupted & Not Found After Migration

by Ken Task -
Picture of Particularly helpful Moodlers

@Lars ... Well, that should fix it - hope it wasn't painful! smile   Too bad we couldn't discover what the issue was.  But, all is well that ends well ... or so am told! :|

'spirit of sharing', Ken