I am using Asp.Net MVC. in my project while uploading PDF file we convert the PDF file into byte then store it in DB. but i got the following exception.
" String or binary data would be truncated.
The statement has been terminated."
Can any one solve this issue.I got the exception righ here
context.SubmitChanges();
Thanks:
Suresh
Just change the size of your field, try varbinary(MAX).
This is most probably because the code attempted to insert more data/bytes in your database column than its defined size.
Related
I have a CSV file that I'm uploading which runs into an issue when importing rows into the database:
Encoding::UndefinedConversionError ("\xCC" from ASCII-8BIT to UTF-8)
What would be the most efficient way to ensure each column is properly encoded for being placed in the database or ignored?
The most basic approach is to go through each row and each field and force encoding on the string but that seems incredibly inefficient. What would be a better way to handle this?
Currently it's just uploaded as a parameter (:csv_file). I then access it as follows:
CSV.parse(csv_file.download) within the model.
I'm assuming there's a way to force the encoding when CSV.parse is called on the activestorage file but not sure how. Any ideas?
Thanks!
The latest version ActiveStorage (6.0.0.rc1) adds an API to be able to download the file to a temp file, which you can then read from. I'm assuming that Ruby will read from the file using the correct encoding.
https://edgeguides.rubyonrails.org/active_storage_overview.html#downloading-files
If you don't want to upgrade to the RC of Rails 6 (like I don't) you can use this method to convert the string to UTF-8 while getting rid of the byte order mark that may be present in your file:
wrongly_encoded_string = active_record_model.attachment.download
correctly_encoded_string = wrongly_encoded_string.bytes.pack("c*").force_encoding("UTF-8")
I need to save image from file to PostgreSQL database as binary. Trying to do it like this:
image_file = File.open("image.png", "rb") { |file| file.read }
Image.create(product_id: product_id, image: image_file)
This code gives me the following error:
string contains null byte
Using paperclip or similar, or converting binary to base64 are not an option.
Try providing us more information, if you're able. I know there was a recent PR for Rails that fixed more superfluous bytea escaping in PostgreSQL. So definitely try updating your system to see if that helps. If it doesn't, please provide us more information if you're able.
Here's a link to the PR
I have generated PDF using CoreGaraphics in which i have passed line by line string which i want in PDF. But now i want to generate it in report format. And the data will vary as it is coming from web service. Report format will have three columns and N no. of rows(depending upon the data).
How to generate it please help.
Thanks in advance.
Got the solution..
http://www.ioslearner.com/generate-pdf-programmatically-iphoneipad/
I have the used above tutorial and in the drawText method, i have used drawInRect: for individual string for particular column.
I suggest you this framework: https://github.com/htsoft/RSReport
I had use a method to redirect all my logs into a text file. The problem is that i do not know how to store the text file into the SQLite database.
I would use Blob fields. here is a description how to do it. And of course the content of the file should be stored. The file itself can be stored elsewhere, with a HTTP POST...
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