我如何在Grails中使用Oracle创建文件上传? [英] how do I create a file upload in grails which works with oracle?
问题描述
遇到以下问题:
我试图在grails中创建一个simpel文件上传功能。我刚刚创建了一个带有
byte [] rawFile
作为属性。 Grails为我做了大部分休息。它在dev环境中的标准hsqldb中运行良好。
然后,我将它部署到配置了oracle db(瘦驱动程序)的服务器上。除了文件上传以外,其他所有的东西都可以很好的与oracle db配合使用对于文件上传,我得到了一个(据我记忆)
SQLException:ORA-01461:只能绑定一个LONG值插入到LONG中
我尝试了几种方法修复它(包括一些到blob的列映射并使用java.sql.blob而不是字节[]),但没有真正的工作,我走了一个方向,我的代码不会再独立于数据库了。
Google并没有真正帮助我和我的grails书籍
将文件保存到磁盘并不是一个好的解决方案,我认为。
所以,这里是我的问题:
我如何在Grails中创建一个与oracle一起工作的文件上传?
更新:获得了一些其他信息。用Oracle的XE版本管理重现问题:
Hibernate为rawFile创建一个VARBINARY(255)列。所以我试图上传一个4字节的文件,它工作。
然后我手动将列的类型更改为blob,并使用更大的文件。
p>然后我添加了
static mapping = {
columns {
rawFile类型:'blob'
}
}
我的域类,它停止工作:
lockquote
ERROR errors.GrailsExceptionResolver - [B不能转换为java.sql.Blob
java.lang.ClassCastException:[B不能转换为java.sql.Blob
: - (
不是将类型设置为blob,而是尝试增加maxSize约束:
static constraints = {
rawFile(maxSize:20 * 1024 * 1024)// 20 MB
// ...
}
got the following problem:
I tried to create a simpel file upload functionality in grails. I just created a domain class with a
byte[] rawFile
as property. Grails did most of the rest for me. It worked fine for the standard hsqldb in the dev environment.
Then I deployed it to the server with an oracle db configured (thin driver). Everything but the file upload works fine with the oracle db. For the file upload I get a (as far as I can remember)
SQLException: ORA-01461: can bind a LONG value only for insert into a LONG
I tried several ways to fix it (including some columnmappings to blobs and using java.sql.blob instead of byte[]) but nothing really worked and I went in a direction where my code wouldn't be db independent anymore.
Google didn't really help me and my grails books don't help too.
Saving the file to the disk isn't a good solution im my opinion.
So here's my question:
how do I create a file upload in grails which works with oracle?
Update: got some additional infos. Managed to reproduce the problem with the XE-Edition of Oracle:
Hibernate creates a VARBINARY(255) column for the rawFile. So I tried to upload a 4 bytes file and it worked.
I then changed the type of the column manually to 'blob' and it worked with bigger files.
I then added
static mapping = {
columns {
rawFile type:'blob'
}
}
to my domain class and it stopped working:
ERROR errors.GrailsExceptionResolver - [B cannot be cast to java.sql.Blob java.lang.ClassCastException: [B cannot be cast to java.sql.Blob
:-(
Instead of setting the type to blob try to increase the maxSize constraint:
static constraints = {
rawFile(maxSize: 20 * 1024 * 1024) // 20 MBs
// ...
}
这篇关于我如何在Grails中使用Oracle创建文件上传?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!