Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 将fileupload formdata转换为base64时的部分字符串_Arrays_Base64_Inputstream_Apache Commons_Fileitem - Fatal编程技术网

Arrays 将fileupload formdata转换为base64时的部分字符串

Arrays 将fileupload formdata转换为base64时的部分字符串,arrays,base64,inputstream,apache-commons,fileitem,Arrays,Base64,Inputstream,Apache Commons,Fileitem,我正在尝试将文件上载表单数据转换为base64。ajax post将表单数据发送到后端 $( "#profileModalForm" ).submit(function( event ) { var formData = new FormData(this); $.ajax({ cache: false, url: 'SaveProfilePopupData.ws', type: "POST", enctype: '

我正在尝试将文件上载表单数据转换为base64。ajax post将表单数据发送到后端

$( "#profileModalForm" ).submit(function( event ) {
    var formData = new FormData(this);
    $.ajax({
        cache: false,
        url: 'SaveProfilePopupData.ws',
        type: "POST",
        enctype: 'multipart/form-data',
        data: formData,        
        contentType: false,
        processData: false,
        success: function (html) {
            $('#notificationArea').html(html);
        }
    });
    event.preventDefault();
});
然后在java端,我尝试使用ApacheCommonsFileUpload读取图像并保存到base64字符串

            ServletFileUpload upload = new ServletFileUpload();
            FileItemIterator iterator = upload.getItemIterator(request);
            while(iterator.hasNext()){
                FileItemStream item = iterator.next();
                InputStream stream = item.openStream();
                if(!item.isFormField()){
                    byte[] str = new byte[stream.available()];
                    stream.read(str);
                    imageBase64String = new String(Base64.getEncoder().encode(str));

                }
            }

我只能获得我上传的图像的部分base64字符串值(在7KB图像中,我只能看到图像的一半)。我做错了什么?

1。您正在使用base64—您很可能不需要使用它。2. <代码>字节[]str=新字节[stream.available()]您只处理立即可用的内容;如果还有更多呢?相关: