if you are using Jersey for file upload and using "@FormDataParam("file") InputStream file" to receive the file and "@FormDataParam("file") FormDataContentDisposition fileDetail" to receive filemetadata then you will run into and issue where fileDetails.getSize() is coming as -1. This will only get populated if the "size" header is passed in multipart request. For me FF was not sending when I was uploading file.
The only way I could make it work was to add a TeeInputStream and calculate the length. I wrote a class
private static class OutputStreamSizeCalculator extends OutputStream {
private long length;
@Override
public void write(int b) throws IOException {
length++;
}
public long getLength() {
return length;
}
}
and then wrapped my InputStream around it
OutputStreamSizeCalculator out = new OutputStreamSizeCalculator();
TeeInputStream tee = new TeeInputStream(in, out, true);
...pass tee to the underlying methods and then call
long length = out.getLength();
The only way I could make it work was to add a TeeInputStream and calculate the length. I wrote a class
private static class OutputStreamSizeCalculator extends OutputStream {
private long length;
@Override
public void write(int b) throws IOException {
length++;
}
public long getLength() {
return length;
}
}
and then wrapped my InputStream around it
OutputStreamSizeCalculator out = new OutputStreamSizeCalculator();
TeeInputStream tee = new TeeInputStream(in, out, true);
...pass tee to the underlying methods and then call
long length = out.getLength();
Comments
Post a Comment