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

Using 'Azure.Storage.Blobs' instead of 'WindowsAzure.Storage' #3414

Merged
merged 2 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions e2e/test/iothub/FileUploadE2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.Threading.Tasks;
using Azure.Storage.Blobs.Models;
using Azure.Storage.Blobs.Specialized;
using FluentAssertions;
using Microsoft.Azure.Devices.Client;
using Microsoft.Azure.Devices.Client.Exceptions;
using Microsoft.Azure.Devices.Client.Transport;
using Microsoft.Azure.Devices.E2ETests.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.WindowsAzure.Storage.Blob;

namespace Microsoft.Azure.Devices.E2ETests
{
Expand All @@ -41,7 +42,7 @@ public async Task FileUpload_SmallFile_Http()
await UploadFileAsync(Client.TransportType.Http1, smallFile).ConfigureAwait(false);
}

[TestMethodWithRetry(Max=3)]
[TestMethodWithRetry(Max = 3)]
[Timeout(TestTimeoutMilliseconds)]
[TestCategory("LongRunning")]
public async Task FileUpload_GetFileUploadSasUri_Http_NoFileTransportSettingSpecified()
Expand All @@ -50,7 +51,7 @@ public async Task FileUpload_GetFileUploadSasUri_Http_NoFileTransportSettingSpec
await GetSasUriAsync(Client.TransportType.Http1, smallFileBlobName).ConfigureAwait(false);
}

[TestMethodWithRetry(Max=3)]
[TestMethodWithRetry(Max = 3)]
[Timeout(TestTimeoutMilliseconds)]
[TestCategory("LongRunning")]
public async Task FileUpload_GetFileUploadSasUri_Http_x509_NoFileTransportSettingSpecified()
Expand All @@ -59,7 +60,7 @@ public async Task FileUpload_GetFileUploadSasUri_Http_x509_NoFileTransportSettin
await GetSasUriAsync(Client.TransportType.Http1, smallFileBlobName, true).ConfigureAwait(false);
}

[TestMethodWithRetry(Max=3)]
[TestMethodWithRetry(Max = 3)]
[Timeout(TestTimeoutMilliseconds)]
[TestCategory("LongRunning")]
public async Task FileUpload_GetFileUploadSasUri_Mqtt_x509_NoFileTransportSettingSpecified()
Expand Down Expand Up @@ -94,7 +95,7 @@ public async Task FileUpload_X509_SmallFile_Http()
await UploadFileAsync(Client.TransportType.Http1, smallFile, true).ConfigureAwait(false);
}

[TestMethodWithRetry(Max=3)]
[TestMethodWithRetry(Max = 3)]
[Timeout(TestTimeoutMilliseconds)]
[TestCategory("LongRunning")]
public async Task FileUpload_SmallFile_Http_GranularSteps()
Expand All @@ -106,7 +107,7 @@ public async Task FileUpload_SmallFile_Http_GranularSteps()
await UploadFileGranularAsync(fileStreamSource, filename, fileUploadTransportSettings).ConfigureAwait(false);
}

[TestMethodWithRetry(Max=3)]
[TestMethodWithRetry(Max = 3)]
[Timeout(TestTimeoutMilliseconds)]
[TestCategory("LongRunning")]
public async Task FileUpload_SmallFile_Http_GranularSteps_x509()
Expand All @@ -118,7 +119,7 @@ public async Task FileUpload_SmallFile_Http_GranularSteps_x509()
await UploadFileGranularAsync(fileStreamSource, filename, fileUploadTransportSettings, useX509auth: true).ConfigureAwait(false);
}

[TestMethodWithRetry(Max=3)]
[TestMethodWithRetry(Max = 3)]
[Timeout(TestTimeoutMilliseconds)]
[TestCategory("LongRunning")]
[TestCategory("Proxy")]
Expand All @@ -135,7 +136,7 @@ public async Task FileUpload_SmallFile_Http_GranularSteps_Proxy()
}

// File upload requests can be configured to use a user-provided HttpClient
[TestMethodWithRetry(Max=3)]
[TestMethodWithRetry(Max = 3)]
public async Task FileUpload_UsesCustomHttpClient()
{
using TestDevice testDevice =
Expand Down Expand Up @@ -205,14 +206,13 @@ private async Task UploadFileGranularAsync(Stream source, string filename, Http1
{
FileUploadSasUriResponse fileUploadSasUriResponse = await deviceClient.GetFileUploadSasUriAsync(fileUploadSasUriRequest).ConfigureAwait(false);

var blob = new CloudBlockBlob(fileUploadSasUriResponse.GetBlobUri());
Task uploadTask = blob.UploadFromStreamAsync(source);
await uploadTask.ConfigureAwait(false);
var blockBlobClient = new BlockBlobClient(fileUploadSasUriResponse.GetBlobUri());
var uploadTask = await blockBlobClient.UploadAsync(source, new BlobUploadOptions()).ConfigureAwait(false);

var notification = new FileUploadCompletionNotification
{
CorrelationId = fileUploadSasUriResponse.CorrelationId,
IsSuccess = uploadTask.IsCompleted
IsSuccess = uploadTask.Value.LastModified.Subtract(DateTimeOffset.Now) <= new TimeSpan(100)
};

await deviceClient.CompleteFileUploadAsync(notification).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Storage.Blobs" Version="12.13.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.19.1" />
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />

Expand Down
2 changes: 1 addition & 1 deletion iothub/device/src/Microsoft.Azure.Devices.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Azure.Storage.Blobs" Version="12.19.1" />
<PackageReference Include="Microsoft.Azure.Amqp" Version="2.5.12" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="WindowsAzure.Storage" Version="9.3.2" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net472' ">
Expand Down
15 changes: 8 additions & 7 deletions iothub/device/src/Transport/Http/HttpTransportHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
using Azure.Storage.Blobs.Specialized;
using Microsoft.Azure.Devices.Client.Exceptions;
using Microsoft.Azure.Devices.Client.Extensions;
using Microsoft.Azure.Devices.Shared;
using Microsoft.WindowsAzure.Storage.Blob;
using Newtonsoft.Json;

namespace Microsoft.Azure.Devices.Client.Transport
Expand Down Expand Up @@ -207,14 +209,13 @@ internal async Task UploadToBlobAsync(string blobName, Stream source, Cancellati
try
{
// 2. Use SAS URI to send data to Azure Storage Blob (PUT)
var blob = new CloudBlockBlob(new Uri(putString));
Task uploadTask = blob.UploadFromStreamAsync(source, null, null, null, cancellationToken);
await uploadTask.ConfigureAwait(false);
var blockBlobClient = new BlockBlobClient(new Uri(putString));
var uploadTask = await blockBlobClient.UploadAsync(source, new BlobUploadOptions(), cancellationToken).ConfigureAwait(false);

notification.CorrelationId = fileUploadResponse.CorrelationId;
notification.IsSuccess = uploadTask.IsCompleted;
notification.StatusCode = uploadTask.IsCompleted ? 0 : -1;
notification.StatusDescription = uploadTask.IsCompleted ? null : "Failed to upload to storage.";
notification.IsSuccess = uploadTask.Value.LastModified.Subtract(DateTimeOffset.Now) <= new TimeSpan(100);
tmahmood-microsoft marked this conversation as resolved.
Show resolved Hide resolved
notification.StatusCode = notification.IsSuccess ? 0 : -1;
notification.StatusDescription = notification.IsSuccess ? null : "Failed to upload to storage.";

// 3. POST to IoTHub with upload status
await _httpClientHelper
Expand Down