Mandando arquivos via webservice

0 respostas
felipe.thiago
Ola pessoal alguem ja fez transferencia de arquivos via webservice? transformei em numa string em base64 Eu fiz mas quando a arquivos muito grandes parece que o arquivo não abre corretamente. Exemplo do codigo abaixo
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;

import org.apache.axis.encoding.Base64;

public class FileTeste
{
	// Metodo de teste que transforma o arquivo em uma String de base 64
	public static void trasformerInByte(File file) throws Exception
	{
		byte[] content;
		try
		{
			byte[] buffer = new byte[8192];

			FileInputStream fis = new FileInputStream(file);

			BufferedInputStream bis = new BufferedInputStream(fis, 8192);

			ByteArrayOutputStream baos = new ByteArrayOutputStream((int) file.length());

			int len = 0;

			while ((len = bis.read(buffer, 0, buffer.length)) != -1)
			{
				baos.write(buffer, 0, len);
			}

			content = baos.toByteArray();
			String stringInBase64 = Base64.encode(content);

			bis.close();
			fis.close();

		}
		catch (Exception e)

		{
			throw new Exception(e);
		}
	}
}

E como converto para File novamente

[code]
try
{
byte[] filecontent = Base64.decode(file);
if (filecontent.length == 0)
{
return "Erro ao converter a String de Base 64 : " + file;
}
catch (Exception e)
{
log.warn("WEBSERVICE ERROR: " + e.getStackTrace());
getStackTrace(e);
return "WEBSERVICE ERROR : " + getStackTrace(e);
}

Criado 16 de julho de 2010
Respostas 0
Participantes 1