boa tarde galera…
eu achei essa classe no JSPBrasil e ela serve pra fazer upload, de imagens…
porem preciso fazer um upload de um txt, fiz alguns testes ela aceita txt, mais com tamanho maximo de 100 kb, tentei altera isso mais não consegui…
alguem poderia me ajudar??
preciso mudar pra uns 5,0mb, pois o txt q estou utilizando eh bem extenso
grato
import java.io.*;
import java.util.*;
public class JSPBrasilUpload {
private final int BUFFERSIZE = 65536;
private final int MAXTOKEN = 8192;
private int action = 10; // 10 - Upload dont't started
// 20 - Upload in action
// 30 - Upload terminated
private int bytesToRead = 50000000;
private String nome="sem_nome.jpg";
private String targetDir = "/tmp";
private Vector allFiles = new Vector(16);
private int upindex = -1;
public boolean uploadFile (InputStream isFromWeb) throws Exception {
DataInputStream disFromWeb = new DataInputStream(isFromWeb);
String boundary = disFromWeb.readLine()+"--";
StringTokenizer stt = new StringTokenizer(disFromWeb.readLine(), ""=
");
stt.nextToken(); stt.nextToken(); stt.nextToken();
if (! stt.hasMoreElements()) return false;
String filename = (new File(stt.nextToken())).getName();
while (!disFromWeb.readLine().equals("")) ;
byte bytesBuffer[] = new byte[BUFFERSIZE+MAXTOKEN];
boolean end = false;
int allBytesRead = 0;
int thisRead = 0;
int lastRead = 0;
int toProcess = 0; // Always equals to MAXTOKEN
FileOutputStream outFileStream = new FileOutputStream(targetDir+"/"+nome/*filename*/); // altera o nome do arquivo quando for graválo no destino
do {
for (int i=0; i < toProcess; i++)
bytesBuffer[i] = bytesBuffer[thisRead+i];
thisRead = toProcess;
int result;
do {
result = disFromWeb.read(bytesBuffer, thisRead, BUFFERSIZE);
} while ((result != -1) && ((thisRead += result) < MAXTOKEN));
if (thisRead > MAXTOKEN) {
thisRead -= MAXTOKEN;
toProcess = MAXTOKEN;
}
else {
thisRead -= boundary.length() + 4 /* CR+LF at 2 last lines */;
end = true;
}
outFileStream.write(bytesBuffer, 0, Math.min(thisRead, bytesToRead - allBytesRead));
allBytesRead += thisRead;
} while ((! end) && (allBytesRead < bytesToRead));
while (disFromWeb.read(bytesBuffer, 0, BUFFERSIZE) != -1) ;
disFromWeb.close();
outFileStream.close();
allFiles.addElement(filename);
return true;
}
public int getBytesToRead() {
return bytesToRead;
}
public void setBytesToRead(int bytesToRead) {
this.bytesToRead = bytesToRead;
}
public String getTargetDir() {
return targetDir;
}
public void setTargetDir(String targetDir) {
this.targetDir = targetDir;
}
public void setNome(String nome) {
this.nome = nome;
}
public int getAction() {
return action;
}
public void setAction(int action) {
this.action = action;
if (action == 10)
allFiles.clear();
}
public boolean getNextUpload() {
if (++upindex < allFiles.size())
return true;
upindex = -1;
return false;
}
public String getUploadFileName() {
return (String) allFiles.elementAt(upindex);
}
}