alexmojaki / s3-stream-upload

Manages streaming of data to AWS S3 without knowing the size beforehand and without keeping it all in memory or writing to disk.
MIT License
208 stars 62 forks source link

Set Content-disposition #22

Closed ghost closed 4 years ago

ghost commented 4 years ago

Hi, Thanks for this lib. I'm using this lib. I need help about set Content-disposition. Can you guide me on how to achieve this? here is my sample code.

String pptxFileName = pptDestination + tempPresentation.getSlides().get_Item(0).getLayoutSlide().getName().replaceAll(" ", "") + ".pptx";
        try {           
            streamTransferManager = new StreamTransferManager(MAIN_ASSET_BUCKET,pptxFileName, s3Client); // Upload data to S3 in Chunks.
            multipartOutputStream = streamTransferManager.getMultiPartOutputStreams().get(0);
            tempPresentation.save(multipartOutputStream, SaveFormat.Pptx);
        } finally {
            if(!multipartOutputStream.equals(null) && !streamTransferManager.equals(null)) {
                multipartOutputStream.close();
                streamTransferManager.complete();               
            }
        }
ghost commented 4 years ago

Its really urgent requirement for me. @alexmojaki could you guide me?

alexmojaki commented 4 years ago

I said in #11 that I didn't think this library was helpful to you as .save() just writes the whole thing in one go. Did you understand that?

Anyway the solution is to subclass StreamTransferManager and override one of the customise*Request methods to set the content disposition: http://alexmojaki.github.io/s3-stream-upload/javadoc/apidocs/alex/mojaki/s3upload/StreamTransferManager.html#customiseCompleteRequest-com.amazonaws.services.s3.model.CompleteMultipartUploadRequest-

alexmojaki commented 4 years ago

Something like this:

    public void customiseInitiateRequest(InitiateMultipartUploadRequest request) {
        request.getObjectMetadata().setContentDisposition("...");
    }
ghost commented 4 years ago

Thanks! @alexmojaki. it's working for me.