diff --git a/sdk/storage/Azure.Storage.Blobs/src/BlobClient.cs b/sdk/storage/Azure.Storage.Blobs/src/BlobClient.cs index 1f8120746542..313bee37db5a 100644 --- a/sdk/storage/Azure.Storage.Blobs/src/BlobClient.cs +++ b/sdk/storage/Azure.Storage.Blobs/src/BlobClient.cs @@ -751,7 +751,7 @@ public virtual Response Upload( StorageTransferOptions transferOptions = default, CancellationToken cancellationToken = default) { - using (FileStream stream = new FileStream(path, FileMode.Open)) + using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read)) { return StagedUploadAsync( stream, @@ -901,7 +901,7 @@ public virtual async Task> UploadAsync( StorageTransferOptions transferOptions = default, CancellationToken cancellationToken = default) { - using (FileStream stream = new FileStream(path, FileMode.Open)) + using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read)) { return await StagedUploadAsync( stream, @@ -1062,7 +1062,7 @@ internal async Task> StagedUploadAsync( bool async = true, CancellationToken cancellationToken = default) { - using (FileStream stream = new FileStream(path, FileMode.Open)) + using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read)) { return await StagedUploadAsync( stream, diff --git a/sdk/storage/Azure.Storage.Blobs/tests/BlobClientTests.cs b/sdk/storage/Azure.Storage.Blobs/tests/BlobClientTests.cs index dafe03cba8c7..3c044759bd27 100644 --- a/sdk/storage/Azure.Storage.Blobs/tests/BlobClientTests.cs +++ b/sdk/storage/Azure.Storage.Blobs/tests/BlobClientTests.cs @@ -261,12 +261,17 @@ public async Task UploadAsync_File() { File.WriteAllBytes(path, data); + // Test that we can upload a read-only file. + File.SetAttributes(path, FileAttributes.ReadOnly); + await blob.UploadAsync(path); + } finally { if (File.Exists(path)) { + File.SetAttributes(path, FileAttributes.Normal); File.Delete(path); } }