Giter Club home page Giter Club logo

Comments (3)

PavelSafronov avatar PavelSafronov commented on June 27, 2024

Thank you very much for providing such an easy-to-use repro case. :)

When filling the MemoryStream, you are not resetting the position to the start of the stream. If you call ms.Position = 0; before constructing the request, the position will reset and the request will succeed. V1 SDK did this, while the V2 SDK does not.

But setting the position is not the only possible solution:

  • Since you already have a FileStream with your data, you can simply set the PutObjectRequest.InputStream to that stream.
  • You can also construct the MemoryStream by passing in a byte array of your data (this would allow you to keep the file open for the shortest possible time). This can be done either by reading the data as you are doing it, or with File.ReadAllBytes.

On an unrelated note, when you are creating an instance of AmazonS3Config you are setting both ServiceURL and RegionEndpoint. You only need to set one of these. (If ServiceURL is set, the SDK ignores RegionEndpoint.) For ease of use, however, I would recommend to just using the RegionEndpoint.

from aws-sdk-net.

evereq avatar evereq commented on June 27, 2024

Wow, thanks for an amazing, quick and right response!
Yep, reset of stream position helps and now console app works too :)
Secret was that in ASP.NET MVC app I do that, however in console app I read data other way (more simple) and fail with it.

I however want to make following notes: think it's good idea to list that (i.e. fact that new version of SDK does not reset stream position anymore) as breaking change because some other developers may step at the same issue (agree however that correct way to remove that line from SDK source code because it's client responsibility to ensure correct position in the stream... i.e. was totally my fault)

Thanks also for Tips about handing of streams for short period of time (they are correct and sample application can be improved with them, however in my production code it's more complicated and optimized already... for example I use async reading from source stream opened from web response instead of file in filesystem etc)

Re: ServiceUrl and RegionEndpoint I just can't found any info and decide to use both :D Now it's clear, thanks!

Thanks again, Amazing work!

🍻

from aws-sdk-net.

evereq avatar evereq commented on June 27, 2024

Hi @PavelSafronov!

Would be amazing if you can take a look into new issue #27 for which same projects with SDK v2 have issues with Content-Encoding headers :)

Thanks!

P.S. hopefully last issue I need to be fixed in v2 to put my site latest version live :)

from aws-sdk-net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.