How decode raw BLOB content from database

Hello all,

I am currently trying to recover FAQ data from a mysql database, as the system is
will be shut down soon :disappointed_relieved: and unfortunately the user interface does not support FAQ export.

Below is a data frame FAQ_RAW , what is the method to decode and save or possibly output the $ content?
The $content includes png, jpeg and pdf data.

As a newbie to rStudio, maybe any of you know of some good literature/tutorials on this topic? :grinning:

> str(FAQ_RAW)
'data.frame':	2 obs. of  11 variables:
 $ id              :integer64 78 79 
 $ faq_id          :integer64 61 61 
 $ filename        : chr  "SH0051 STAWS NHK sitzt fest.pdf" "image.png"
 $ content_size    : chr  "1172454" "295778"
 $ content_type    : chr  "application/pdf" "image/png; name=\"image.png\""
 $ content         :List of 2
  ..$ : raw  25 50 44 46 ...
  ..$ : raw  89 50 4e 47 ...
 $ inlineattachment: int  0 1
 $ created         : POSIXct, format: "2020-03-18 12:42:12" "2020-03-18 12:42:12"
 $ created_by      : int  6 6
 $ changed         : POSIXct, format: "2020-03-18 12:42:12" "2020-03-18 12:42:12"
 $ changed_by      : int  6 6

Thank you in advance

If you are lucky you may be able to simply write out the file from its raw with base::writeBin()
(readBin: Transfer Binary Data To and From Connections)

i try
but get the message Can only write vector objects

FAQ_RAW is a big list of things that arent the raws, its all the metadata too.
try to write the first item the SH0051 pdf
also I would want to write it out to a file connection (so that I could try to open the file) rather than write it to binary data stored in some variable.
so look into file connections.
something like

myfile <- file("mynewfile.pdf","rwb")

but not guarantees, its hard to now how the raw data in content within FAQ got made and therefore the right thing / possible things to do with it.

the results :

> myfile <- file("mynewfile.pdf","rwb")
Error in file("mynewfile.pdf", "rwb") : cannot open the connection
In addition: Warning message:
In file("mynewfile.pdf", "rwb") :
  cannot open file 'mynewfile.pdf': No such file or directory

it is not necessary to create the file mynewfile.pdf first ?

Plan B would be to do the job of downloading to a directory using php script.
UPDATE: Plan B works fine :slight_smile:

Last Question: Is there a method to trigger PHP script with R?

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.