|
|
@ -22,7 +22,9 @@ import mx.gob.jumapacelaya.models.RedmineUser; |
|
|
|
import mx.gob.jumapacelaya.services.UserService; |
|
|
|
import mx.gob.jumapacelaya.views.MainLayout; |
|
|
|
|
|
|
|
import java.io.ByteArrayOutputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
@ -66,24 +68,39 @@ public class CrearnuevoTicketView extends VerticalLayout { |
|
|
|
descripcion.setHeight("250px"); |
|
|
|
|
|
|
|
// Campo para adjuntar archivos |
|
|
|
buffer = new MemoryBuffer(); |
|
|
|
uploadFile = new Upload(buffer); |
|
|
|
uploadFile.setAcceptedFileTypes("image/jpeg", "image/png", "application/pdf"); |
|
|
|
MemoryBuffer buffer = new MemoryBuffer(); |
|
|
|
Upload uploadFile = new Upload(buffer); |
|
|
|
uploadFile.setAcceptedFileTypes("image/jpeg", "image/png", "application/pdf", "image/gif", "image/svg", "text/plain", |
|
|
|
"application/zip", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", |
|
|
|
"application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
|
|
|
|
|
|
|
uploadFile.addSucceededListener(event -> { |
|
|
|
if (buffer.getFileData() != null) { |
|
|
|
try { |
|
|
|
byte[] fileContent = buffer.getInputStream().readAllBytes(); |
|
|
|
String fileName = buffer.getFileName(); |
|
|
|
fileUploadToken = api.uploadFile(fileContent, fileName); |
|
|
|
if (fileUploadToken == null) { |
|
|
|
logger.error("Error al obtener el token del archivo"); |
|
|
|
} else { |
|
|
|
logger.error("Archivo subido exitosamente. Token obtenido: " + fileUploadToken); |
|
|
|
String fileName = buffer.getFileName(); |
|
|
|
InputStream inputStream = buffer.getInputStream(); |
|
|
|
|
|
|
|
if (fileName != null && inputStream != null) { |
|
|
|
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { |
|
|
|
// Lee los bytes del archivo |
|
|
|
byte[] bufferArray = new byte[1024]; |
|
|
|
int bytesRead; |
|
|
|
while ((bytesRead = inputStream.read(bufferArray)) != -1) { |
|
|
|
outputStream.write(bufferArray, 0, bytesRead); |
|
|
|
} |
|
|
|
byte[] fileContent = outputStream.toByteArray(); |
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
Notification.show("Error al leer el archivo: " + e.getMessage(), 3000, Notification.Position.MIDDLE); |
|
|
|
logger.error("Error al leer el archivo: " + e.getMessage()); |
|
|
|
} finally { |
|
|
|
try { |
|
|
|
inputStream.close(); |
|
|
|
} catch (IOException e) { |
|
|
|
logger.error("Error al cerrar el InputStream: " + e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
Notification.show("Error: Nombre de archivo o contenido nulos", 3000, Notification.Position.MIDDLE); |
|
|
|
logger.error("Error: Nombre de archivo o contenido nulos"); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|