How to upload the file by java?

How to upload the file by java?

F.TorresF.Torres Posts: 12Questions: 4Answers: 0

some of my recent research,I know how to display the file,But the key is I can't get the stream in the server,and the file must save in the database? and must create a table to save the file id、path and so on?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    I'm afraid I know next to nothing about Java. You'd need to ask in a Java specific programming forum or StackOverflow about how to read a file from an HTTP upload.

    Regards,
    Allan

  • F.TorresF.Torres Posts: 12Questions: 4Answers: 0

    by this code,I can attribute the name and id to the input where type = text
    attr:{
    name:"imgUrl",
    id:"imgUrl"
    }
    but I can't attribute the input where type = 'file'

  • F.TorresF.Torres Posts: 12Questions: 4Answers: 0

    by attr id and name,I think I can send the stream to the server

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    The upload field type is what Editor uses for file upload.

    Allan

  • F.TorresF.Torres Posts: 12Questions: 4Answers: 0

    I think the api is to little...
    and Should I attr the enctype="multipart/form-data" in the form?
    but I can't find

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin
    Answer ✓

    No - the upload field type uses XHR requests to upload the document. Documentation for it is available here.

    Allan

  • F.TorresF.Torres Posts: 12Questions: 4Answers: 0
    edited May 2017
    {
                label:"课件封面",
                name:"imgUrl",
                type:"upload",
                action : getRootPath()+"/back/club_course_upload.do",
                uploadField : "imgUrl",
                upload : $(".upload input")[0],????????
                dragDrop: false,//禁用拖拽上传功能
                display: function ( val, row ) {
                    /*return val && row.image.webPath ?
                        '<img src="'+row.image.webPath+'"/>' :
                        'No image';*/
                },
                noFileText: '没有文件',//没有文件显示的文字
                //drawCallback: function () {
                    //var formData = new FormData();
                    //formData.append("file",$(jQuery(".upload input"))[0].files[0]);    
                    ajax:{
                        url:getRootPath()+"/back/club_course_upload.do",
                        type:"post",
                        action:"upload",
                        uploadField:"imgUrl",
                        upload: $(".upload input")[0],
                        data: {
                            "data": new FormData($(".upload input")[0]),
                            //"url": $(".upload input")[0].value
                        },
                        //contentType: false,
                        success: function (data) {
                            if (data.status == "true") {
                                alert("上传成功!");
                            }
                            if (data.status == "error") {
                                alert(data.msg);
                            }
                            $("#imgWait").hide();
                            alert(data);
                        },
                        error: function (data) {
                            alert(data);
                        }
                    }
                //}
                
            }
    

    I don't know what should I write by the upload,It is display the type is the File!

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    That presumably shows a upload field type and let's you select a file, correct? Then when you select the file it sends the file to getRootPath()+"/back/club_course_upload.do", correct?

    Allan

  • F.TorresF.Torres Posts: 12Questions: 4Answers: 0

    I can debug with the path,but I can't get the stream

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    I don't really know what you mean I'm afraid. The stream in Java? As I say, I know next to nothing about Java - you'd need to ask on StackOverflow or a Java specific forum.

    Allan

  • F.TorresF.Torres Posts: 12Questions: 4Answers: 0

    Your answer it's true,my understanding of editor is not deep enough,and it makes me a lot of trouble,thanks by your answer although I often can't express myself clearly.

This discussion has been closed.