Correctly identify file upload in multipart and only parse the first file upload

This commit is contained in:
Sean Owen 2014-09-12 15:35:29 +01:00
parent 53d562f7c9
commit 5adcb269ad

View file

@ -16,10 +16,6 @@
package com.google.zxing.web; package com.google.zxing.web;
import com.google.common.collect.Lists;
import com.google.common.io.Resources;
import com.google.common.net.HttpHeaders;
import com.google.common.net.MediaType;
import com.google.zxing.BarcodeFormat; import com.google.zxing.BarcodeFormat;
import com.google.zxing.BinaryBitmap; import com.google.zxing.BinaryBitmap;
import com.google.zxing.ChecksumException; import com.google.zxing.ChecksumException;
@ -35,10 +31,14 @@ import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.client.j2se.ImageReader; import com.google.zxing.client.j2se.ImageReader;
import com.google.zxing.common.GlobalHistogramBinarizer; import com.google.zxing.common.GlobalHistogramBinarizer;
import com.google.zxing.common.HybridBinarizer; import com.google.zxing.common.HybridBinarizer;
import com.google.zxing.multi.GenericMultipleBarcodeReader; import com.google.zxing.multi.GenericMultipleBarcodeReader;
import com.google.zxing.multi.MultipleBarcodeReader; import com.google.zxing.multi.MultipleBarcodeReader;
import com.google.common.collect.Lists;
import com.google.common.io.Resources;
import com.google.common.net.HttpHeaders;
import com.google.common.net.MediaType;
import java.awt.color.CMMException; import java.awt.color.CMMException;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.IOException; import java.io.IOException;
@ -265,14 +265,19 @@ public final class DecodeServlet extends HttpServlet {
errorResponse(request, response, "badimage"); errorResponse(request, response, "badimage");
return; return;
} }
if (parts.isEmpty()) { Part fileUploadPart = null;
for (Part part : parts) {
if (part.getHeader(HttpHeaders.CONTENT_DISPOSITION) != null) {
fileUploadPart = part;
break;
}
}
if (fileUploadPart == null) {
log.info("File upload was not multipart"); log.info("File upload was not multipart");
errorResponse(request, response, "badimage"); errorResponse(request, response, "badimage");
return; } else {
}
for (Part part : parts) {
log.info("Decoding uploaded file"); log.info("Decoding uploaded file");
try (InputStream is = part.getInputStream()) { try (InputStream is = fileUploadPart.getInputStream()) {
processStream(is, request, response); processStream(is, request, response);
} }
} }