The servlet has this code:
try { List<FileItem> multiparts = new ServletFileUpload( new DiskFileItemFactory()).parseRequest(request); BufferedImage image = null; byte[] imageByte; for(FileItem item : multiparts){ if(!item.isFormField()){ String name = new File(item.getName()).getName(); item.write( new File("C:\\temp" + File.separator + name)); BASE64Decoder decoder = new BASE64Decoder(); imageByte = decoder.decodeBuffer(File.separator + name); ByteArrayInputStream bis = new ByteArrayInputStream(imageByte); image = ImageIO.read(bis); System.out.println(Arrays.toString(imageByte)); System.out.println(image); bis.close(); } } } catch (Exception ignore) { } I'm trying to encode image base64 but my image why it is null , what am I doing wrong?
{ id: "upl1", view: "uploader", icon: "upload", type: "iconButton", label: "Загрузить", width: 110, align: 'center', multiple: false, link: "mylist", formData: {}, on: { onBeforeFileAdd: function (item) { this.define('formData', {fileName: item.name}); var type = item.type.toLowerCase(); if (type != "png" && type != "jpg"){ messageBox('Ошибка', "Только png или jpg файлы"); return false; } }, onAfterFileAdd: function (item) { }, onUploadComplete: function (response) { // uploadComplete(response); } }, upload: "/labMarket/import" } Here is the client code. The servlet sees the picture, test - saves to the specified folder. But decode fails.
String decode = Base64 .getEncoder() .encodeToString( (name) .getBytes() );try it like this - Senior Pomidor