Can you explain why you are accessing the InputStream and the problem you are trying to solve at a high level so we are not guessing? Seems like you are trying to forward the stream? If that's the case then you'll need to read the stream into a buffer
and forward the buffer.
Can you explain why you are accessing the InputStream and the problem you are trying to solve at a high level so we are not guessing?
Sir, because my class takes stream as a parameter.
public bool sendMyFileToS3(System.IO.Stream localFilePath, string bucketName, string subDirectoryInBucket, string fileNameInS3)
{
IAmazonS3 client = new AmazonS3Client(RegionEndpoint.APSouth1);
TransferUtility utility = new TransferUtility(client);
TransferUtilityUploadRequest request = new TransferUtilityUploadRequest();
if (subDirectoryInBucket == "" || subDirectoryInBucket == null)
{
request.BucketName = bucketName; //no subdirectory just bucket name
}
else
{ // subdirectory and bucket name
request.BucketName = bucketName + @"/" + subDirectoryInBucket;
}
request.Key = fileNameInS3; //file name up in S3
request.InputStream = localFilePath;
utility.Upload(request); //commensing the transfer
return true; //indicate that the file was sent
}
It is our choices, that show what we truly are, far more than our abilities.
Participant
1446 Points
2839 Posts
stream.ReadTimeout' threw an exception of type 'System.InvalidOperationException
Jun 18, 2019 06:08 PM|demoninside9|LINK
Hi All,
I am using below code to upload file.
I got the error st.ReadTimeout' threw an exception of type 'System.InvalidOperationException on the below line
Stream st = FileUpload1.PostedFile.InputStream;
Please suggest
All-Star
53641 Points
23992 Posts
Re: stream.ReadTimeout' threw an exception of type 'System.InvalidOperationException
Jun 18, 2019 06:41 PM|mgebhard|LINK
File upload in Web Forms is well documented with wonderful examples that work perfectly.
https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.fileupload?view=netframework-4.8
Can you explain why you are accessing the InputStream and the problem you are trying to solve at a high level so we are not guessing? Seems like you are trying to forward the stream? If that's the case then you'll need to read the stream into a buffer and forward the buffer.
Participant
1446 Points
2839 Posts
Re: stream.ReadTimeout' threw an exception of type 'System.InvalidOperationException
Jun 18, 2019 07:11 PM|demoninside9|LINK
Sir, because my class takes stream as a parameter.
All-Star
53641 Points
23992 Posts
Re: stream.ReadTimeout' threw an exception of type 'System.InvalidOperationException
Jun 18, 2019 07:40 PM|mgebhard|LINK
That's a a design detail not the high-level problem you are trying to solve.
I'm pretty sure in ASP.NET you need to read the file stream into a buffer first. Then pass the buffer to the sendMyfilesToS3() method.
https://docs.microsoft.com/en-us/dotnet/api/system.web.httppostedfile.inputstream?view=netframework-4.8
Have you verified the sendMyfilesToS3() works? I would expect a content-length so the receiver know how many bytes to expect.
Participant
1446 Points
2839 Posts
Re: stream.ReadTimeout' threw an exception of type 'System.InvalidOperationException
Jun 19, 2019 06:52 AM|demoninside9|LINK
Now it is working fine, without any issue.
Only the issue is that I am saving first it on my root's local folder that uploading to bucket. like below
Because without this I am not getting the file path. I was willing to upload it directly without saving on my root's folder
Contributor
3710 Points
1043 Posts
Re: stream.ReadTimeout' threw an exception of type 'System.InvalidOperationException
Jun 19, 2019 08:04 AM|Yongqing Yu|LINK
Hi demoninside,
According to your requirements and the code your provided, it is not permissible that put the inputstream directly into Amazon s3 client.
I suggest you could change your InputStream into byte[], then proceed to your next steps.
Here is the mehod about how to make inputStream into byte[] :
Best Regards,
YongQing.
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.