martes, 14 de marzo de 2017

Combos Dependientes en Spring MVC primefaces



En Img anterior se muestra el ejemplo que vamos a trabajar con Spring MVC y Primefaces para los combos dependientes de la tabla UBIGEO

viernes, 3 de marzo de 2017

Subir archivo a Cloud Amazon S3 desde java


Servicio de almacenamiento de información basada en la web de  Amazon S3 está experimentando problemas generalizados, llevando al servicio que está parcial o totalmente roto en sitios web, aplicaciones y dispositivos en los que se basa. La oferta de AWS ofrece hosting de imágenes para un montón de sitios y también alberga sitios web y app backends como nido.



import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.CannedAccessControlList;
import com.amazonaws.services.s3.model.PutObjectRequest;
import java.io.File;
import java.io.IOException;



public class prueba {
     private static String bucketName = "carpeta";
         private static String keyName = "sub carpeta mas el nombre del archivo";
 

    // ruta del archivo
    private static String uploadFileName = "c:\\hh\\USUARIOS.DB";
 

    private static String s3Url = "";
 
       public static void main(String[] args)  throws IOException{
         
        BasicAWSCredentials awsCredentials = new BasicAWSCredentials("usuario","clave");
        AmazonS3Client s3client = new AmazonS3Client(awsCredentials);
     
        Region usEast1 = Region.getRegion(Regions.US_EAST_1);
        s3client.setRegion(usEast1);
        try {
         
            System.out.println("Uploading a new object to S3 from a file\n");
            File file = new File(uploadFileName);
            s3client.putObject(new PutObjectRequest(
                    bucketName, keyName, file));
            s3client.setObjectAcl(bucketName, keyName, CannedAccessControlList.PublicRead);
            s3Url = s3client.getResourceUrl(bucketName, keyName);
            System.out.println("S3 Url:       " + s3Url);

        } catch (AmazonServiceException ase) {
            System.out.println("Caught an AmazonServiceException, which " +
                    "means your request made it " +
                    "to Amazon S3, but was rejected with an error response" +
                    " for some reason.");
            System.out.println("Error Message:    " + ase.getMessage());
            System.out.println("HTTP Status Code: " + ase.getStatusCode());
            System.out.println("AWS Error Code:   " + ase.getErrorCode());
            System.out.println("Request ID:       " + ase.getRequestId());
            System.out.println("Error Type:       " + ase.getErrorType());
        } catch (AmazonClientException ace) {
            System.out.println("Caught an AmazonClientException, which " +
                    "means the client encountered " +
                    "an internal error while trying to " +
                    "communicate with S3, " +
                    "such as not being able to access the network.");
            System.out.println("Error Message: " + ace.getMessage());
        }
       }
}