Azure Storage Copy From Blob - azure

I am having an issue converting the Console app described here .Copying an existing blob into a media services asset to run on mobile app service
I have everything like for like refernces wise and code wise but have the following issue
// Display the size of the source blob.
Console.WriteLine(sourceBlob.Properties.Length);
Console.WriteLine(string.Format("Copy blob '{0}' to '{1}'", sourceBlob.Uri, destinationBlob.Uri));
// The line below gives the following error:
destinationBlob.StartCopyFromBlob(new Uri(sourceBlob.Uri.AbsoluteUri + signature));
Blockquote
'ICloudBlob' does not contain a definition for 'StartCopyFromBlob' and no extension method 'StartCopyFromBlob' accepting a first argument of type 'ICloudBlob' could be found (are you missing a using directive or an assembly reference?
Is this because i am using version 7 of the storage client and the method has been removed?
If so is there a new method of combination of methods that i can use to achieve a similar result?

From the release notes, you can find:
Blobs: Removed deprecated (Begin/End)StartCopyFromBlob(Async) APIs in favor of using (Begin/End)StartCopy(Async) APIs.
Therefore, please use StartCopy instead of StartCopyFromBlob.

As Zhaoxing Lu said that 'ICloudBlob' does not contain a definition for 'StartCopy'. Base on your code, you could find 'StartCopy' in CloudBlockBlob class.
According to the tutorial you mentioned, you could modify the type of destinationBlob:
CloudBlockBlob destinationBlob = destinationContainer.GetBlockBlobReference(sourceBlob.Name);
Instead of:
ICloudBlob destinationBlob = destinationContainer.GetBlockBlobReference(sourceBlob.Name);
Note: CloudBlobContainer.GetBlockBlobReference returns a CloudBlockBlob object.
Then you could run the following code:
destinationBlob.StartCopy(new Uri(sourceBlob.Uri.AbsoluteUri + signature));

Related

What is the difference between BlobAttribute vs BlobTriggerAttribute?

Can anyone elaborate on the difference between BlobAttribute vs BlobTriggerAttribute?
[FunctionName(nameof(Run))]
public async Task Run(
[BlobTrigger("container/{name}")]
byte[] data,
[Blob("container/{name}", FileAccess.Read)]
byte[] data2,
string name)
{
}
https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob?tabs=csharp#trigger
It seems BlobTrigger has all the functionality.
From the doc you could find the main difference is the blob contents are provided as input with BlobTrigger. It means it could only read the blob, not able to write the blob.
And the the BlobAttribute supports binding to single blobs, blob containers, or collections of blobs and supports read and write.
Also the BlobTrigger could only be used to read the blob when a new or updated blob is detected. And the Blob binding could be used in every kind function.
Further more information about these two binding you could check the binding code: BlobAttribute and BlobTriggerAttribute.

want to create a Azure Logic App expression

In Azure Logic App, I am creating blob event grid. I am able to get event whenever I have added or deleted a blob from a storage account. In that I am getting the below responses.
In the Subject i am getting response as '/blobServices/default/containers/james/blobs/catputvendor/Capture.PNG'
Now I need to write an expression which gets below result.
'/james/catputvendor/Capture.PNG'.
Which expression is best.
I got below expression using c# working but in logic app expression, we don't have Remove method. How I need to do in logic app as following:
var subStri1 = str.Remove(str.IndexOf("/blobs"), "/blobs".Length).Substring(str.Remove(str.IndexOf("/blobs"), "/blobs".Length).LastIndexOf("/containers") + "/containers".Length);
The Subject in the Dynamic content, it's the absolute path about the blob. So you could use split expression to get the path you want.
And the expression would be like this:split(triggerBody()?['subject'], '/')?[4]. My subject path is /blobServices/default/containers/firstcontainer/blobs/test/Snipaste_2018-11-13_10-08-08.png. So the expression will get the container name firstcontainer.
So the whole expression will be
#{split(triggerBody()?['subject'], '/')?[4]}/#{split(triggerBody()?['subject'], '/')?[6]}/#{split(triggerBody()?['subject'],'/')?[7]}.
Here is my flow and the result page.
Hope this could help you, if you still have other questions, please let me know.

Azure Blob Storage : buffer cannot be null

I'm following the source code from Xamarin for Azure : FileUploader for Image Upload , and I try to run the app, the error shown the buffer cannot be null.
as shown below:
I suggest, Creating "MemoryStream object" and assign using stream.CopyTo(), return byte[] using "memorystream object".ToArray()
If you don't want to change the code as above,
1. Check the value of "stream.Length"
2. Add some padding (extras) to it e.g. byte[] buffer = new byte[stream.Length+10]
3. Also, check if you can read the stream using .CanRead()

Adding PartitionKey propery when inserting an entity in Azure table storage for nodejs

This is more of a call for help with an exception when calling insertEntity().
I'm using Nodejs on Azure and editing in Monaco, and I've NPM-installed the latest version of azure storage.
The exception I encounter is: (full stack trace at the bottom)
Unaught exception: Error: Parameter entityDescriptor.PartitionKey for function entityOperation should be an object at ArgumentValidator._.extend.object
I'm basically taking my object to save, and creating 2 new properties: PartitionKey and RowKey. I give them string values. I'm following the examples. I'm not using entityGenerator, as the samples here don't, whereas the examples on the Azure Node developers portal do. I wouldn't mind using entityGenerator on the storage-specific properties if required, but the samples in the node azure github repo seem to suggest that you can use simple strings. The entityGenerator looks a bit ugly and cumbersome, honestly, as you'd have to code extra around the entity when you bring it back.
How can I adjust my code to solve this problem and call insertEntity() with success?
exports.saveTally = function(tally, callback) {
var tableSvc = getAzureTableService();
tableSvc.createTableIfNotExists("tally", function(error, result, response) {
if (!error) {
tally.PartitionKey="tally";
tally.RowKey = tally.id;
tableSvc.insertEntity("tally", tally, function(error, result, response) {
if (error) {
console.log("*Error saving tally " + error.toString());
}
else {
callback(tally.id);
}
});
}
});}
The location of the Azure storage client library has changed to https://github.com/Azure/azure-storage-node. The samples you’re using are from the old location and from an older version of the library which is why they’re not working. You’ll find updated samples and code at the new location.
In the newer version, an Edm type must be specified for each table entity. This is because type is stored in the storage service and we want to make sure that we are storing what you intend. Each table entity is an object with the form {_:value, $:Edm.Type}.
Entity generator is a convenience feature which makes it simpler to construct table entity objects. We return entities in the form just mentioned and using this convenience feature will not change that in any way.

Set metadata in REST request to put blob in AZURE

i am able to upload file to azure blob using REST api provided by Azure.
i want to set metadata at the time i am doing request for put blob, when i am setting it into header as shown here i am unble to upload file and getting following exception org.apache.http.client.ClientProtocolException.
from the last line of the code below
HttpPut req = new HttpPut(uri);
req.setHeader("x-ms-blob-type", blobType);
req.setHeader("x-ms-date", date);
req.setHeader("x-ms-version", storageServiceVersion);
req.setHeader("x-ms-meta-Cat", user);
req.setHeader("Authorization", authorizationHeader);
HttpEntity entity = new InputStreamEntity(is,blobLength);
req.setEntity(entity);
HttpResponse response = httpClient.execute(req);
regarding the same, i have two questions.
can setting different metadata, avoid overwriting of file? See my question for the same here
if Yes for first question, how to set metadata in REST request to put blob into Azure?
please help
So a few things are going here.
Regarding the error you're getting, it is because you're not adding your metadata header when calculating authorization header. Please read Constructing the Canonicalized Headers String section here: http://msdn.microsoft.com/en-us/library/windowsazure/dd179428.aspx.
Based on this, you would need to change the following line of code (from your blog post)
String canonicalizedHeaders = "x-ms-blob-type:"+blobType+"\nx-ms-date:"+date+"\nx-ms-version:"+storageServiceVersion;
to
String canonicalizedHeaders = "x-ms-blob-type:"+blobType+"\nx-ms-date:"+date+"\nx-ms-meta-cat"+user+"\nx-ms-version:"+storageServiceVersion;
(Note: I have just made these changes in Notepad so they may not work. Please go to the link I mentioned above for correctly creating the canonicalized headers string.
can setting different metadata, avoid overwriting of file?
Not sure what you mean by this. You can update metadata of a blob by performing Set Blob Metadata operation on a blog.

Resources