Example usage for com.amazonaws.services.s3.model GeneratePresignedUrlRequest setResponseHeaders

List of usage examples for com.amazonaws.services.s3.model GeneratePresignedUrlRequest setResponseHeaders

Introduction

In this page you can find the example usage for com.amazonaws.services.s3.model GeneratePresignedUrlRequest setResponseHeaders.

Prototype

public void setResponseHeaders(ResponseHeaderOverrides responseHeaders) 

Source Link

Document

Sets the headers to be overridden in the service response.

Usage

From source file:br.org.fiscal65.amazonaws.AWSPictureUpload.java

License:Open Source License

public AWSPictureUpload(Context context, OnPictureUploadS3PostExecuteListener uploadListener,
        String picturePath, String slugFiscalizacao, String zonaFiscalizacao, Long idFiscalizacao,
        Integer posicaoFoto, Integer podeEnviarRedeDados, Integer sleep) {
    super(context);

    this.uploadListener = uploadListener;

    this.picturePath = picturePath;

    this.slugFiscalizacao = slugFiscalizacao;

    this.zonaFiscalizacao = zonaFiscalizacao;

    this.idFiscalizacao = idFiscalizacao;

    this.posicaoFoto = posicaoFoto;

    this.podeEnviarRedeDados = podeEnviarRedeDados;

    this.sleep = sleep;

    mStatus = Status.IN_PROGRESS;/*w ww  .  j a  va  2s  . com*/

    progressListener = new ProgressListener() {
        @Override
        public void progressChanged(ProgressEvent event) {
            if (event.getEventCode() == ProgressEvent.COMPLETED_EVENT_CODE) {
                boolean hasInternet = CommunicationUtils.verifyConnectivity(getContext());

                if (hasInternet) {
                    boolean isOnWiFi = CommunicationUtils.isWifi(getContext());

                    if (isOnWiFi || (AWSPictureUpload.this.podeEnviarRedeDados != null
                            && AWSPictureUpload.this.podeEnviarRedeDados.equals(1))) {
                        try {
                            ResponseHeaderOverrides override = new ResponseHeaderOverrides();
                            override.setContentType("image/jpeg");

                            GeneratePresignedUrlRequest urlRequest = new GeneratePresignedUrlRequest(
                                    CommunicationConstants.PICTURE_BUCKET_NAME,
                                    AWSUtil.getPrefix(getContext()) + AWSPictureUpload.this.slugFiscalizacao
                                            + "/zona-" + AWSPictureUpload.this.zonaFiscalizacao + "/"
                                            + pictureName);
                            urlRequest.setResponseHeaders(override);

                            URL urlDaFoto = AWSUtil.getS3Client(getContext()).generatePresignedUrl(urlRequest);

                            if (urlDaFoto != null) {
                                String string = urlDaFoto.toString();
                                String[] parts = string.split("\\?");
                                String url = parts[0];

                                S3UploadPictureResult result = new S3UploadPictureResult();
                                result.setUrlDaFoto(url);
                                result.setPosicaoFoto(AWSPictureUpload.this.posicaoFoto);
                                result.setIdFiscalizacao(AWSPictureUpload.this.idFiscalizacao);
                                result.setSlugFiscalizacao(AWSPictureUpload.this.slugFiscalizacao);
                                result.setZonaFiscalizacao(AWSPictureUpload.this.zonaFiscalizacao);

                                mStatus = Status.COMPLETED;
                                AWSPictureUpload.this.uploadListener
                                        .finishedPictureUploadS3ComResultado(result);
                            } else {
                                mStatus = Status.CANCELED;

                                if (mUpload != null) {
                                    mUpload.abort();
                                }

                                AWSPictureUpload.this.uploadListener.finishedPictureUploadS3ComError(
                                        AWSPictureUpload.this.slugFiscalizacao,
                                        AWSPictureUpload.this.zonaFiscalizacao,
                                        AWSPictureUpload.this.idFiscalizacao,
                                        AWSPictureUpload.this.posicaoFoto);
                            }
                        } catch (Exception e) {
                            mStatus = Status.CANCELED;

                            if (mUpload != null) {
                                mUpload.abort();
                            }

                            AWSPictureUpload.this.uploadListener.finishedPictureUploadS3ComError(
                                    AWSPictureUpload.this.slugFiscalizacao,
                                    AWSPictureUpload.this.zonaFiscalizacao,
                                    AWSPictureUpload.this.idFiscalizacao, AWSPictureUpload.this.posicaoFoto);
                        }
                    } else {
                        mStatus = Status.CANCELED;

                        if (mUpload != null) {
                            mUpload.abort();
                        }

                        AWSPictureUpload.this.uploadListener.finishedPictureUploadS3ComError(
                                AWSPictureUpload.this.slugFiscalizacao, AWSPictureUpload.this.zonaFiscalizacao,
                                AWSPictureUpload.this.idFiscalizacao, AWSPictureUpload.this.posicaoFoto);
                    }
                } else {
                    mStatus = Status.CANCELED;

                    if (mUpload != null) {
                        mUpload.abort();
                    }

                    AWSPictureUpload.this.uploadListener.finishedPictureUploadS3ComError(
                            AWSPictureUpload.this.slugFiscalizacao, AWSPictureUpload.this.zonaFiscalizacao,
                            AWSPictureUpload.this.idFiscalizacao, AWSPictureUpload.this.posicaoFoto);
                }
            } else if (event.getEventCode() == ProgressEvent.FAILED_EVENT_CODE) {
                mStatus = Status.CANCELED;

                if (mUpload != null) {
                    mUpload.abort();
                }

                AWSPictureUpload.this.uploadListener.finishedPictureUploadS3ComError(
                        AWSPictureUpload.this.slugFiscalizacao, AWSPictureUpload.this.zonaFiscalizacao,
                        AWSPictureUpload.this.idFiscalizacao, AWSPictureUpload.this.posicaoFoto);
            }
        }
    };
}

From source file:modules.storage.AmazonS3Storage.java

License:Open Source License

@Override
public F.Promise<Result> getDownload(String key, String name) {
    GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucketName, key);
    ResponseHeaderOverrides responseHeaders = new ResponseHeaderOverrides();
    responseHeaders.setContentDisposition("attachment; filename=" + name);
    generatePresignedUrlRequest.setResponseHeaders(responseHeaders);

    AmazonS3 amazonS3 = new AmazonS3Client(credentials);

    try {/*from  ww  w. j a  v  a2s  . c  o  m*/
        URL url = amazonS3.generatePresignedUrl(generatePresignedUrlRequest);

        return F.Promise.pure(redirect(url.toString()));
    } catch (AmazonClientException ace) {
        logAmazonClientException(ace);
        return F.Promise.pure(internalServerError(error.render()));
    }
}