We are storing uploaded text files in a SQL server data. The field type is image.
The file upload and download correctly, what I want to do now is load the actual text content into a String variable directly from the database record.
Can anyone advise on how to do this please?
Depends on how you read the data from the db. If you get a byte array, you could use new String(bytes);
Btw, why don't you use the CLOB datatype (or the equivalent for your server) for the field? This should normally cause the Java driver to return the String directly.
Related
I'm using osmnavigator, and I'm trying to retrieve raw kml from the sqlite but couldn't find any solution. Can I store the filename only and retrieve on parsekmlstream?
If you can get an InputStream on what you want to read, then you should be able to use KmlDocument method:
public boolean parseKMLStream(InputStream stream, ZipFile kmzContainer)
(just pass null for the kmzContainer param)
I need to upload an image from android app to a java server. I tried to define the type image like a string and to convert the image, that the user can upload from documents or take with camera, into a base64 string. But when i convert this image in base64 and put this inside a string to save it in database, server give me a 500 internal sever error and this error message:
"com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'image' at row 1"
The Db is in Mysql and i use this from java server.
So, how can I save a base64 image to my server? Can I use a different type?
Thank you!
you can use volley library. for more details these links are useful
first_link and second_link
I have a very specific requirement of storing PDF data in Hbase columns. The source of Data is Mongo DB, from where the base64 encoded data is read and I will need to bulk upload it to Hbase table.
I realized that in base64 encoded string there are a lot of "\n" character which splits the entire string into parts. Not sure if it is because of this, but when I store the string as it is, using a put :
put.add(Bytes.toBytes(ColFamilyName), Bytes.toBytes(columnName), Bytes.toBytes(data.replaceAll("\n","").toString()));
It is storing only the first line from the entire encoded string. Eg :
If the actual content was something like this :
"JVBERi0xLjQKJaqrrK0KNCAwIG9iago8PAovQ3JlYXRvciAoQXBhY2hlIEZPUCBWZXJzaW9uIDEu
" +
"MSkKL1Byb2R1Y2VyIChBcGFjaGUgRk9QIFZlcnNpb24gMS4xKQovQ3JlYXRpb25EYXRlIChEOjIw\n" +
"MTUwODIyMTIxMjM1KzAzJzAwJykKPj4KZW5kb2JqCjUgMCBvYmoKPDwKICAvTiAzCiAgL0xlbmd0\n" +
It is storing only the first line which is :
JVBERi0xLjQKJaqrrK0KNCAwIG9iago8PAovQ3JlYXRvciAoQXBhY2hlIEZPUCBWZXJzaW9uIDEu
in the column. Even after trying to remove the "\n" manually it is the same output.
Could someone please guide me in the right direction here ?
Currently, I am also working on Base64 encoding. As per my understanding, you should try using
org.apache.hadoop.hbase.util.Base64.encodeBytes(byte[] source, int option)
method where DONT_BREAK_LINES can be used as an option.
Please let me know if this works fine.
Managed to solve it. The issue was when reading the Base64 encoded data from MongoDB Source. Read the data from Mongo DB document DBObject as:
jsonObj.get("receiptContent").toString().replaceAll("\n","")
And stored it as such in Hbase. Even from the Hue HBase UI Browser I can see the PDF content now.
I am reading encoded data from database. When I decode data I get something like
%PDF-1.3
23 Obj
xref
10000000 123n
.
.
.
.
%EOF
I am guessing it's a metadata of PDF file with data. My question is how do I create PDF file out of this with readable data only.
Thanks in advance.
First you need to know what the data in DB represents. I would suggest to connect to the database using a general client. For example, for Oracle - SqlDeveloper, for MS Sql Server - Visual Sql Server, etc
Display the table which has a column of type long, clob or blob and try to save it to a file. Name the file with an extension .pdf. Try to open the saved file and see if it gets open correctly by a pdf reader.
If this is a case, saving it from Java is trivial. For example: http://www.astral-consultancy.co.uk/cgi-bin/hunbug/doco.cgi?11120
I want to create a download link but the part I'm having trouble is that the source is a Java string. The String I have is a JSON data. I want people to be able to download that data.
I am using the Play! framework so I can pass the String data using the Scala template. But I'm not sure how to allow users to download the String and append the file types (.txt, .json) so that users actually download a file.
How do I go about to doing this?
I can't believe how simple the solution is. This was what did it for me. Basically take the string and convert it into an InputStream.
String data = "someBigOrSmallData";
InputStream dataStream = new ByteArrayInputStream(data.getBytes());
response().setHeader("Content-disposition","attachment; filename=anyFileName.txt");
return ok(dataStream);