1

I've implemented a .ashx handler which receives chunked upload parts of a file from the client. Previously I first stored the files in a temp folder before uploading them to AWS. As the files have become quite big, I'd like to skip the temp folder part and upload them directly to AWS using the MultiPart requests.

It looks fine so far, but I can't find an overload which accepts either the HttpPostedFile or Stream for the upload..

I something like the following possible?

        // Create request to upload a part.
        UploadPartRequest uploadRequest = new UploadPartRequest()
            .WithBucketName(myBucket)
            .WithKey(myKey)
            .WithUploadId(myUploadId)                
            .WithPartNumber(partNumber)
            .WithInputStream(inputStream); 

3 Answers 3

2
UploadPartRequest uploadRequest = new UploadPartRequest()
        .WithBucketName(myBucket)
        .WithKey(myKey)
        .WithUploadId(myUploadId)                
        .WithPartNumber(partNumber)
        .WithInputStream(stream) as UploadPartRequest;

This is also possible.

Sign up to request clarification or add additional context in comments.

Comments

1

WithInputStream will return s3 request instead of UploadPartRequest so just cast the return type to UploadPartRequest

// Create request to upload a part.
        UploadPartRequest uploadRequest = new UploadPartRequest()
            .WithBucketName(myBucket)
            .WithKey(myKey)
            .WithUploadId(myUploadId)                
            .WithPartNumber(partNumber);

uploadRequest = (UploadPartRequest)uploadRequest.WithInputStream(ftiObject.sourceStream); 

this works for me

Comments

0

Simple: Just set the Input Stream via the Property:

            // Create request to upload a part.
            UploadPartRequest uploadRequest = new UploadPartRequest()
                .WithBucketName(myBucket)
                .WithKey(myKey)
                .WithUploadId(UploadId)
                .WithPartNumber(PartNumber)
                .WithPartSize(inputStream.Length)
                .WithFilePosition(FilePosition);

            uploadRequest.InputStream = inputStream;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.