Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nonseekable stream can not be uploaded to Object storage #214

Open
jeffhli opened this issue Jan 18, 2024 · 0 comments
Open

Nonseekable stream can not be uploaded to Object storage #214

jeffhli opened this issue Jan 18, 2024 · 0 comments
Labels
SDK Issue pertains to the SDK itself and not specific to any service

Comments

@jeffhli
Copy link

jeffhli commented Jan 18, 2024

The following code will throw an exception that
Oci.Common.Model.OciException
HResult=0x80131500
Message=v2-chunked-transfer-encoding
Source=OCI.DotNetSDK.Common
StackTrace:
at Oci.Common.Http.Internal.ResponseHelper.HandleNonSuccessfulResponse(HttpResponseMessage responseMessage, ApiDetails apiDetails, String caller)
at Oci.Common.Http.RestClient.CheckHttpResponseMessage(HttpRequestMessage httpRequest, HttpResponseMessage httpResponse, ApiDetails apiDetails)
at Oci.ObjectstorageService.ObjectStorageClient.d__48.MoveNext()
at Program.<

$>d__0.MoveNext() in D:\code\localtest\OraclePlayground\Program.cs:line 37

  • NonseekableStream
internal class NonseekableStream : Stream
    {
        private Stream innerStream;

        public NonseekableStream(Stream innerStream)
        {
            this.innerStream = innerStream;
        }

        public override bool CanRead => innerStream.CanRead;

        public override bool CanSeek => false;

        public override bool CanWrite => false;

        public override long Length => innerStream.Length;

        public override long Position { get => innerStream.Position; set => throw new NotSupportedException(); }

        public override void Flush()
        {
            throw new NotSupportedException();
        }

        public override int Read(byte[] buffer, int offset, int count)
        {
            return innerStream.Read(buffer, offset, count);
        }

        public override long Seek(long offset, SeekOrigin origin)
        {
            throw new NotSupportedException();
        }

        public override void SetLength(long value)
        {
            throw new NotSupportedException();
        }

        public override void Write(byte[] buffer, int offset, int count)
        {
            throw new NotSupportedException();
        }
    }
  • Main code
var objectStorageClient = new ObjectStorageClient(provider);
var uri = objectStorageClient.GetEndpoint();
var bucketResponse = await objectStorageClient.GetBucket(new GetBucketRequest()
{
    NamespaceName = "ax1hhmmvkvpo",
    BucketName = "jefftest"
});
var bucket = bucketResponse.Bucket;
var putObjectResponse = await objectStorageClient.PutObject(new PutObjectRequest()
{
    NamespaceName = "ax1hhkmvkvpo",
    BucketName = "jefftest",
    PutObjectBody = new NonseekableStream(new MemoryStream(Encoding.UTF8.GetBytes("Hello, World2!"))),
    ObjectName = "test.txt",

});
@github-anurag github-anurag added the SDK Issue pertains to the SDK itself and not specific to any service label Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SDK Issue pertains to the SDK itself and not specific to any service
Projects
None yet
Development

No branches or pull requests

2 participants