Welcome to Aspire Knowledge Central (AKC)
Home Public Library Author Content
Questions, Feedback
You can post questions related to any of the following technologies
Java
J2EE
XML
Dotnet
Programming
SQL
Html
CSS
Binary Data and Multipart Encoding
Hi, back again...
Any sample on how aspire would go about
saving/retrieving binary data from a
database, say for instance mysql blobs?
It might be a stretch, but does aspire
have a reader/parser support for multipart data?
More on Binary Data and Multipart Encoding
Seems to me aspire doesn't have a prewritten way of handling binary
data. The way i understand it, blobs are returned as strings, therefore,
you are only limited to text files? Of course, I could be mistaken.
As for multipart encoding, there seems to be some kind of support,
but I have no idea how it is used.
Sorry, the notifier is broken and i havent seen your message
Let me look into it. I will let you know. You can email me in the future if you are not able to get answers here quick enough. satya at activeintellect.com
I will get you some information on this
for multipart I have used the commons library for file uploading. For binary data in databases, people have written some independent java parts to handle those. If you show me how you intend to use them perhaps I can show you how to write a part to handle them or I can write one for you that is general enough.
Even for the multipart let me know what need are you going to address other than file uploads.
Binary Data for Databases
Consider for instance a catalog of diagrams or photography catalog..
Although i have used the commons library for file uploading,
I was wondering how this would be possible to insert data
into a blob field while still staying within the aspire
framework.
I am currently using the DBHashTableFormHandler1
(to parse form data) and DBRequestExecutor2 (to insert into database)...
Will it be necessary to write a custom form handler for this?
or is there a simpler way?
Hi, let me answer tomorrow
Hi, let me answer tomorrow
Sorry I haven't had a chance to look at, in the next day or two
Sorry I haven't had a chance to look at, in the next day or two
I had a way to handle file uploads before commons, but I don't think that is flexible
I had a way to handle file uploads before commons, but I don't think that is flexible
So, most likely I will have to write a part using commons
Approach for writing the part will be
Derive from AHttpPart a new part called CommonsFileUploadPart
Specify a directory to the CommonsFileUploadPart to drop the files in
Or give variable names to these files so that they can be placed in a jdbc call to the database
I will try to write the part this weekend
I will try to write the part this weekend
But how are you planning on using it???
Assume you have put a blob in the database. How are you planning on retrieving it and showing it on the browser? Don't you have to stream it? It can be done but is that what you want? will it not work better if you store the files on a file system under a certain directory and place the filename in the database.
Here is how we kind of used it before...
* Example properties file
* ************************
* request.uploadFileRequest.classname=com.ai.htmlgen.DbPreTranslateArgsMultiRequestExecutor
* request.uploadFileRequest.request.db=your-db-alias
* request.uploadFileRequest.request.1=saveFile
* request.uploadFileRequest.request.2=saveFilenameInDatabase
* request.uploadFileRequest.redirectUrl=ShowResults
*
* request.saveFile.classname=com.indent.actions.portlets.SingleFileUploadPart
* request.saveFile.fileUploadFormFieldName=filename
* request.saveFile.targetFilename_WS=aspire:\\mydir\\{user}\\{foldername}}\\abc.txt
* request.saveFile.resultName=fullfile_name
*
* request.saveFilenameInDatabase.classname=com.ai.db.DBRequestExecutor2
* request.saveFilenameInDatabase.query_type=update
* request.saveFilenameInDatabase.stmt=(your insert statement)
synopsis
This code will save a single uploaded file to a specific directory and saves that file name in the database as a reference.
Trouble with this is the access to that file...
THe hope is that you will publish a url to that file for end users to see. If you let the webserver serve that file then access to that file is crude as in either you give all access or no access at all.
If finer control is needed then (i think) you will have to implement some kind of a "file streamer" class or a "databases streamer" class that can take into account access and also setting the file types or content types to the browser.
I Can write the parts fairly quickly, but ...
I Can write the parts fairly quickly, I am wondering if you have some bandwidth to test them, especially the "BLOB" functionality. Let me know.
GQ I have done the coding, and you can read it here
How to upload a file to a database and bring it back
I have done some basic testing. But I will upload the jar file some time this weekend. But hopefully you have the idea and let me know how you intend to use it.