All Products
Search
Document Center

Object Storage Service:What do I do if the size of an object uploaded to OSS by using MemoryStream of OSS SDK for .NET is displayed as zero?

Last Updated:Mar 20, 2026

When you use MemoryStream to upload an object with OSS SDK for .NET, the upload succeeds but the object size shows as 0. This happens because the default file pointer position in MemoryStream is at the end of the stream. When OSS reads from the current pointer position, it reads zero bytes.

Object size displayed as 0 in OSS console

Solution

Before calling the upload method, reset the file pointer to the beginning of the stream:

mStream.Seek(0, SeekOrigin.Begin);

The following example shows a complete upload using MemoryStream with the pointer reset applied:

Code example showing mStream.Seek(0, SeekOrigin.Begin) before upload

After adding mStream.Seek(0, SeekOrigin.Begin), OSS reads the full stream content and the object size is displayed correctly.

Object size displayed correctly after applying the fix