I am trying to upload the file that I have stored in MemoryStream using the following code.
private static void SaveStream(MemoryStream stream, string fileName)
{
var blobStorageService = new BlobStorageService();
UploadBlob(stream, fileName);
}
public void UploadBlob(MemoryStream fileStream,string fileName)
{
var blobContainer = _blobServiceClient.GetBlobContainerClient(Environment
.GetEnvironmentVariable("ContainerName"));
var blobClient = blobContainer.GetBlobClient(fileName);
blobClient.Upload(fileStream); <--- Error Message
}
Error Message: System.ArgumentException: 'content.Position must be less than content.Length.Please set content.Position to the start of the data to upload.'
Blob storage is optimized for storing massive amounts of unstructured data, such as text or binary data. Blob storage is ideal for: Serving images or documents directly to a browser. Storing files for distributed access.
Upload contents of a folder to Data Box Blob storage To get your account key, in the Azure portal, go to your storage account. Go to Settings > Access keys, select a key, and paste it into the AzCopy command. If the specified destination container does not exist, AzCopy creates it and uploads the file into it.
This happened because the current position is at the end of the stream. You can set the position to the start of the stream before uploading
var blobClient = blobContainer.GetBlobClient(fileName);
fileStream.Position =0;
blobClient.Upload(fileStream)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With