How to store content of text area from nicEdit with formatted text in a database - nicedit

I am using the nicEdit editor for a text area, which may have text, image, links and other formated text. I don't know what datatype to use in a MySQL database to store its content.
If there is any other way to handle this stuff, please suggest.

You can try to save the data in a text column. I think it is a good idea to encode the data before saving. For example, save it as base64 (if you don't have to search in the content), or as url encoded string.
If the images are uploaded to the server, you have to save the images on the webserver too. A few options are:
Use Blob fields (binary large objects) to save the images
Convert the images to an base64 string directly for use in the html code.
Save the images on the file system, not the database
In my tests, options 1 and 2 create a lot of data. So it is better to save the images on outside the database.
Hope this Helps.

Related

Finding file type of NSData recieved from server

I am receiving a text file from a socket over TCP/IP. There is no file extension (or filename for that matter) as the data is received as bytes. I can take the data from this (in the form of NSData) and load it into a UITextView and display it fine.
I want to persist this data to a file. However, I don't know what format the data is in (txt, rtf, doc, docx)? I assume it as .txt and save it in the documents directory, but is there a programmatic way of finding out for sure? I've looked around StackOverflow and at the documentation and haven't been able to find anything.
And is there a way to get the details of the file attributes like the file creation date.
Thanks in advance.
When you send a file over a TCP/IP connection, only the file contents will be converted to data and be passed across. If you want the filename,extension and the file attributes, then you will have to add those details separately and append it with the data to be sent. Then you can parse it at the receiver end and use the results inside your app.
You can choose the file type you want when you save the data, you can get attributes from file,please refer to Get file creation date.

Getting the raw base64 content out of an attachment in Indy?

So I have an attachment on my incoming Pop3 message,
Msg.MessageParts.Items[msgpart] as TidAttachmentFile
but, is it possible to get the content of this attached file in the format specified by Msg.MessageParts.Items[msgpart].ContentTransfer (so base64 ascii) instead of creating a temp file, calling SaveToFile, and then re-reading the file and re-connverting back to base64?
If TIdMessage.NoDecode is set to False, then no, it is not possible. When NoDecode is False, TIdMessageClient decodes the email as it is being read off the socket and places decoded binary data into attachment objects. The only way to get the original base64 data is to set TIdMessage.NoDecode to True and parse the raw email data manually (it is stored as-is in the TIdMessage.Body) as you would effectively be disabling TIdMessageClient's entire decoding system.
On the other hand, if you just want to avoid the temp file, you can use the TIdMessage.OnCreateAttachment event to have Indy create TIdAttachmentMemory objects instead of the default TIdAttachmentFile objects. The base64 will still be auto-decoded and stored as binary in the attachment, but at least the attachment would be solely in memory so your re-encode would be faster.

What Character encoding is this?

When i backup my blackberry using blackberry desktop mananger, it saves it as an .ipd file.
its in hex... Not sure if its any particular type. But i used software called ABC amber Text Converter to convert this .ipd file into plain text format. And some of it comes out as plain text, Like all the messages saved in the backup file. But some of the text in the file looks like this:
qÖ²u_+;¢õ¿B[[¤†D`Ø,>p
|Cñ:ÌQ†nÁä¼sÒ®sKDv©{(]
)++³É«.gsn>
z
'‚51o4Kq
8Ütâ¯cí¿þ2´Õ|5kl$S,H
dbiIjz
*!~k$|
&*OÝ>0ðî­wã
+zno%q
2k;
YnÁÅŸ5|Xñ7Ú<}y2
A
V܉lO5‰<œtÅRI-I
Does anybody have any idea What the hell this is or if there is Any way i can decode this?
Thanks
It's just binary data. You may have been able to extract some text from the file where strings of text were stored, but the rest will be just bytes of data.
You'll need a specific program that understands these backup files. A quick google reveals a few choices, such as MagicBerry.
One of the Blackberry developers has helpfully blogged a bit of information about the binary format, so you could try using that to write your own program to parse it:
http://us.blackberry.com/devjournals/resources/journals/jan_2006/ipd_file_format.jsp

Data sanitization and DB storage

If I have the following data, what is the best option in terms of Database storage.
Here is text&lt;br&gt;&lt;br&gt;Here is some more text
I see that I have 3 options:
Store in DB as it is then decode at runtime: <p>hello</p>
Decode and then store in DB: <p>hello</p>
Strip tags completely: Hello
Are there any big "No No's" with any of the above, just looking for some advice on best practice. Also worth noting that I will have absolutely no control over the data that I receive.
Depending on your requirement, I suggest to either strip the tags or store the unencoded version.
If you don't need the tags, the you can strip them and store the plain text.
If you need to preserve the tags and the formatting, then it's easier to save the unencoded version. Dealing with real tags it's much simpler.
Also, it's a view responsibility to encode the output. In fact, it strictly depends on where you are going to print the string.
In the console, for example, tags doesn't create any issue. It's just when you need to print the string into an HTML view. But fortunately Rails takes care of output sanitization for you, so you don't need to store the sanitized version in the database.
Convert the data to canonical form, and store that. That is, you should store <p>Hello</p> or Here is text<br><br>Here is some more text (though I doubt that's the decoding you intended for your example).
Then, you can search without having to worry about how it was encoded (Ö, Ö or Ö, for example?), and just encode it to whatever format is appropriate for display on rendering.

php symfony to get blob image data from mysql

How can I get image data string from mysql db that has blob images? Thanks.
Assuming that you're using the default ORM (Propel) that comes with Symfony, $your_object->getImage()* should return whatever blob value you stored in the database.
You might already know this and it's not an option, but have you considered storing the images in a directory and using the database to store the path to the images ?
*Assuming 'image' is the field name in the database/schema.yml
There is always flamewar about storing images in a database vs. filesystem.
Storing them in a database is more secure (if you need to secure access to them) but usually you need wrapper to read and display them in tag (if you do it).
There's a lot of pros and cons... Depends on your needs what is better.
and yes sjobe's $x->getImage() would be enough to get a blob content.

Resources