Reputation: 3580
I am calling an API which returns a path to GET a TIF image, with authentication included.
The path works, both in Postman and in my browser.\
I'd like to upload it to Azure blob storage.
Image sizes are a few K.
I'm generating a GUID, a7a67740-b809-48e0-a154-686c54c649d6 in this case, and uploading to a container with a legal name, using a connection to Azure blob storage which worked fine in other classes in this project.
Unfortunately, when I try to upload the image with this code:
CloudBlockBlob blockBlob = container.GetBlockBlobReference($"{blobName}.tif");
await blockBlob.UploadFromFileAsync(tif.ToString());
it's throwing me this error:
System.ArgumentException: Illegal characters in path.
at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)
at System.IO.Path.GetFileName(String path)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
at Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.BeginUploadFromFile(String path, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext, AsyncCallback callback, Object state) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Blob\CloudBlockBlob.cs:line 963
at Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.BeginUploadFromFile(String path, AsyncCallback callback, Object state) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Blob\CloudBlockBlob.cs:line 938
at Microsoft.WindowsAzure.Storage.Core.Util.AsyncExtensions.TaskFromVoidApm[T1](Func`4 beginMethod, Action`1 endMethod, T1 arg1, CancellationToken cancellationToken) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Core\Util\AsyncExtensions.cs:line 174
at Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.UploadFromFileAsync(String path, CancellationToken cancellationToken) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Blob\CloudBlockBlob.cs:line 1065
at Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.UploadFromFileAsync(String path) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Blob\CloudBlockBlob.cs:line 1053
at DbMgr.AstroDigital.<GetTasksAsync>d__1.MoveNext() in C:\Users\BaruchKogan\Documents\Visual Studio 2017\Projects\DbMgr\DbMgr\AstroDigital.cs:line 147
Upvotes: 0
Views: 467
Reputation: 136379
blockBlob.UploadFromFileAsync
requires you to specify a path to file on the local computer. Because you're specifying a URL there, you're getting this error.
From your question, it seems that the URL you're getting is publicly accessible i.e. you can take the URL and copy it in browser's address bar and you will see the image. If that is the case, then you should use CopyBlob
method to create the blob using this URL.
CloudBlockBlob blockBlob = container.GetBlockBlobReference($"{blobName}.tif");
await blockBlob.StartCopyAsync(tif);//Assuming "tif" is an object of type System.Uri
What Azure Storage service will do is read the contents of this image from the URI and create a block blob with that.
Upvotes: 2