
CREATE COLUMN TABLE "MYSCHEMA"."IMAGE_STORE"(
"IMAGE_NAME" NVARCHAR(100),
"IMAGE_CONTENT" BLOB MEMORY THRESHOLD 1000,
PRIMARY KEY (
"IMAGE_NAME"
)
) UNLOAD PRIORITY 5 AUTO MERGE;
<u:FileUploader id="fileUploader" name="myFileUpload" uploadUrl="" width="400px" tooltip="Upload your file to the local server" uploadComplete="handleUploadComplete"/>
<Button text="Upload File" press="handleUploadPress"/>
handleUploadPress: function(oEvent) {
var oFileUploader = this.getView().byId("fileUploader");
// Combine the URL with the filename....
oFileUploader.setUploadUrl("../MyXSJS_Listener/SaveImage.xsjs?filename=" + oFileUploader.getValue());
oFileUploader.upload();
},
var schema_name = "MYSCHEMA";
var filename = $.request.parameters.get('filename');
try {
var conn = $.db.getConnection();
var pstmt = conn.prepareStatement("INSERT INTO \"MYSCHEMA\".\"IMAGE_STORE\" (IMAGE_NAME, IMAGE_CONTENT) VALUES (?, ?)");
if($.request.entities.length>0) {
// Read in the posted image or binary data as an Array Buffer - you can use this to save as a BLOB
var file_body = $.request.entities[0].body.asArrayBuffer();
pstmt.setString(1,filename); // Set the file name
pstmt.setBlob(2,file_body); // Set the Blob as the array buffer that has the image data
pstmt.execute();
}
else
{
$.response.setBody("No Entries in request");
}
pstmt.close();
conn.commit();
conn.close();
$.response.contentType = "text/html";
$.response.setBody("[200]:Upload for file" + filename + " was successful!");
}
catch(err)
{
if (pstmt !== null)
{
pstmt.close();
}
if (conn !== null)
{
conn.close();
}
$.response.contentType = "text/html";
$.response.setBody("File could not be saved in the database. Here is the error:" + err.message);
}
I hope this helps anyone looking to do something similar.
Thanks,
Jay
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
11 | |
10 | |
9 | |
7 | |
5 | |
5 | |
4 | |
4 | |
3 | |
3 |