【问题标题】:how to save large files inside the data base.?如何将大文件保存在数据库中。?
【发布时间】:2012-05-19 12:08:47
【问题描述】:

我正在使用 JSP 表单上传和 Servlet 将大型文件存储在 MySQL 数据库中。而且因为我一般是 Java 新手,所以我需要一个非常紧急的帮助。 我试图将文件存储在字符串值中,但出现字符串索引超出边界的错误。

我有具有 (varchar File_Name, Blob File_data, Varchar File_Date) 的数据库表 Files。 我需要将上传的文件存储在

我在 servlet 中有这段代码: ** 顺便说一句:我不知道为什么“DiskFileUpload,parseRequest”有删除线?

 try {
         InputStream uploadedFile = null;

         <strike>DiskFileUpload</strike> fu = new </strike>DiskFileUpload</strike>();
        // If file size exceeds, a FileUploadException will be thrown
        fu.setSizeMax(10000000);

        List fileItems = fu.<strike>parseRequest</strike>(request);
        Iterator itr = fileItems.iterator();

        while (itr.hasNext()) {
            FileItem fi = (FileItem) itr.next();

            //Check if not form field so as to only handle the file inputs
            //else condition handles the submit button input
            if (!fi.isFormField()) {  // If the form fiel is a file
                uploadedFile = fi.getInputStream();
            } 

我应该转换什么类型的数据 uploadFile cvariable 能够将其存储在 Blob 属性中?

【问题讨论】:

    标签: java mysql database servlets file-upload


    【解决方案1】:

    删除意味着 API 已被弃用,这些类/方法可能无法按预期工作。

    将文件存储到数据库,您需要将内容作为字节存储在 blob 文件中。请参阅此discussion。即使它与某些错误有关,OP 也发布了有关如何执行此操作的代码。

    【讨论】:

    • 我该如何克服这个问题?
    猜你喜欢
    • 2011-07-20
    • 2012-08-21
    • 1970-01-01
    • 2022-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-23
    • 2016-11-04
    相关资源
    最近更新 更多