我已经实现了一个.ashx处理程序,它从客户端接收文件的分块上传部分。以前我首先将文件存储在临时文件夹中,然后再将它们上传到AWS。 由于文件变得非常大,我想跳过临时文件夹部分并使用MultiPart请求将它们直接上传到AWS。
到目前为止它看起来很好,但我找不到接受HttpPostedFile或Stream上传的重载..
我可能会遇到以下情况?
// Create request to upload a part.
UploadPartRequest uploadRequest = new UploadPartRequest()
.WithBucketName(myBucket)
.WithKey(myKey)
.WithUploadId(myUploadId)
.WithPartNumber(partNumber)
.WithInputStream(inputStream);
答案 0 :(得分:2)
UploadPartRequest uploadRequest = new UploadPartRequest()
.WithBucketName(myBucket)
.WithKey(myKey)
.WithUploadId(myUploadId)
.WithPartNumber(partNumber)
.WithInputStream(stream) as UploadPartRequest;
这也是可能的。
答案 1 :(得分:1)
WithInputStream将返回s3请求而不是UploadPartRequest 所以只需将返回类型转换为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);
这对我有用
答案 2 :(得分:0)
简单:只需通过属性设置输入流:
// 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;