Rename blob then save new
up vote
0
down vote
favorite
I am trying to use Xamarin Blob to save the new version of a image after renaming the previous one.
for example my old image is in the container named "imagecontainer" and has Id named like "xama_452"
what I would like to do is :
1- Rename the old image name : for example 'xama_452_11_2018"
2-Move it in a container "oldcontainer"
3- then save the new image in "imagecontainer"
I have tried some code I can upload a image/blob but I cannot rename it and move it to another container.
protected static async Task<CloudBlockBlob> SaveBlockBlob(string containerName, byte blob, string blobTitle)
{
var blobContainer = GetBlobContainer(containerName);
var blockBlob = blobContainer.GetBlockBlobReference(blobTitle);
var oldBlob = blobContainer.GetBlockBlobReference(blockBlob.Uri.ToString());
var newBlob = blobContainer.GetBlockBlobReference(blockBlob.Uri.ToString().Replace(blobTitle, DateTime.UtcNow.ToString()+ blobTitle));
await newBlob.StartCopyAsync(oldBlob);
// here is the methode to upload
// await blockBlob.UploadFromByteArrayAsync(blob, 0, blob.Length).ConfigureAwait(false);
return blockBlob;
}
// method to get blob's container
static CloudBlobContainer GetBlobContainer(string containerName) => BlobClient.GetContainerReference(containerName);
Thanks in advance
c# azure xamarin.forms azure-active-directory azure-storage
add a comment |
up vote
0
down vote
favorite
I am trying to use Xamarin Blob to save the new version of a image after renaming the previous one.
for example my old image is in the container named "imagecontainer" and has Id named like "xama_452"
what I would like to do is :
1- Rename the old image name : for example 'xama_452_11_2018"
2-Move it in a container "oldcontainer"
3- then save the new image in "imagecontainer"
I have tried some code I can upload a image/blob but I cannot rename it and move it to another container.
protected static async Task<CloudBlockBlob> SaveBlockBlob(string containerName, byte blob, string blobTitle)
{
var blobContainer = GetBlobContainer(containerName);
var blockBlob = blobContainer.GetBlockBlobReference(blobTitle);
var oldBlob = blobContainer.GetBlockBlobReference(blockBlob.Uri.ToString());
var newBlob = blobContainer.GetBlockBlobReference(blockBlob.Uri.ToString().Replace(blobTitle, DateTime.UtcNow.ToString()+ blobTitle));
await newBlob.StartCopyAsync(oldBlob);
// here is the methode to upload
// await blockBlob.UploadFromByteArrayAsync(blob, 0, blob.Length).ConfigureAwait(false);
return blockBlob;
}
// method to get blob's container
static CloudBlobContainer GetBlobContainer(string containerName) => BlobClient.GetContainerReference(containerName);
Thanks in advance
c# azure xamarin.forms azure-active-directory azure-storage
1
Possible duplicate of Azure Storage Blob Rename
– Jayendran
Nov 11 at 13:07
It it not the sae I want to rename the old image file , if you can help me
– kikis
Nov 11 at 15:24
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to use Xamarin Blob to save the new version of a image after renaming the previous one.
for example my old image is in the container named "imagecontainer" and has Id named like "xama_452"
what I would like to do is :
1- Rename the old image name : for example 'xama_452_11_2018"
2-Move it in a container "oldcontainer"
3- then save the new image in "imagecontainer"
I have tried some code I can upload a image/blob but I cannot rename it and move it to another container.
protected static async Task<CloudBlockBlob> SaveBlockBlob(string containerName, byte blob, string blobTitle)
{
var blobContainer = GetBlobContainer(containerName);
var blockBlob = blobContainer.GetBlockBlobReference(blobTitle);
var oldBlob = blobContainer.GetBlockBlobReference(blockBlob.Uri.ToString());
var newBlob = blobContainer.GetBlockBlobReference(blockBlob.Uri.ToString().Replace(blobTitle, DateTime.UtcNow.ToString()+ blobTitle));
await newBlob.StartCopyAsync(oldBlob);
// here is the methode to upload
// await blockBlob.UploadFromByteArrayAsync(blob, 0, blob.Length).ConfigureAwait(false);
return blockBlob;
}
// method to get blob's container
static CloudBlobContainer GetBlobContainer(string containerName) => BlobClient.GetContainerReference(containerName);
Thanks in advance
c# azure xamarin.forms azure-active-directory azure-storage
I am trying to use Xamarin Blob to save the new version of a image after renaming the previous one.
for example my old image is in the container named "imagecontainer" and has Id named like "xama_452"
what I would like to do is :
1- Rename the old image name : for example 'xama_452_11_2018"
2-Move it in a container "oldcontainer"
3- then save the new image in "imagecontainer"
I have tried some code I can upload a image/blob but I cannot rename it and move it to another container.
protected static async Task<CloudBlockBlob> SaveBlockBlob(string containerName, byte blob, string blobTitle)
{
var blobContainer = GetBlobContainer(containerName);
var blockBlob = blobContainer.GetBlockBlobReference(blobTitle);
var oldBlob = blobContainer.GetBlockBlobReference(blockBlob.Uri.ToString());
var newBlob = blobContainer.GetBlockBlobReference(blockBlob.Uri.ToString().Replace(blobTitle, DateTime.UtcNow.ToString()+ blobTitle));
await newBlob.StartCopyAsync(oldBlob);
// here is the methode to upload
// await blockBlob.UploadFromByteArrayAsync(blob, 0, blob.Length).ConfigureAwait(false);
return blockBlob;
}
// method to get blob's container
static CloudBlobContainer GetBlobContainer(string containerName) => BlobClient.GetContainerReference(containerName);
Thanks in advance
c# azure xamarin.forms azure-active-directory azure-storage
c# azure xamarin.forms azure-active-directory azure-storage
asked Nov 11 at 10:41
kikis
186
186
1
Possible duplicate of Azure Storage Blob Rename
– Jayendran
Nov 11 at 13:07
It it not the sae I want to rename the old image file , if you can help me
– kikis
Nov 11 at 15:24
add a comment |
1
Possible duplicate of Azure Storage Blob Rename
– Jayendran
Nov 11 at 13:07
It it not the sae I want to rename the old image file , if you can help me
– kikis
Nov 11 at 15:24
1
1
Possible duplicate of Azure Storage Blob Rename
– Jayendran
Nov 11 at 13:07
Possible duplicate of Azure Storage Blob Rename
– Jayendran
Nov 11 at 13:07
It it not the sae I want to rename the old image file , if you can help me
– kikis
Nov 11 at 15:24
It it not the sae I want to rename the old image file , if you can help me
– kikis
Nov 11 at 15:24
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
1- Rename the old image name : for example 'xama_452_11_2018"
Due to the lack of API to rename the blob file on Azure, you could set newBlobName with the format you want and copy the source to the destination. Refer to this article.
2-Move it in a container "oldcontainer"
You could get the desctionation container's blob to copy the source. Refer to this one.
3- then save the new image in "imagecontainer"
Upload blob to the sourcecontainer. Refer to this article.
The whole codes are as below:
public static void RenameBlob(string containerName, string destContainer,string blobName,string newblobname)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer imgcontainer = cloudBlobClient.GetContainerReference(containerName);
string name = blobName.Split('.');
//rename blob
string newBlobName = name[0] + "_"+DateTime.Now.ToString("MM")+"_"+DateTime.Now.ToString("yyyy") + "." + name[1];
CloudBlobContainer oldcontainer = cloudBlobClient.GetContainerReference(destContainer);
if (!oldcontainer.Exists())
{
throw new Exception("Destination container does not exist.");
}
CloudBlockBlob blobCopy = oldcontainer.GetBlockBlobReference(newBlobName);
if (!blobCopy.Exists())
{
CloudBlockBlob blob = imgcontainer.GetBlockBlobReference(blobName);
if (blob.Exists())
{
//move blob to oldcontainer
blobCopy.StartCopy(blob);
blob.Delete();
}
}
//upload blob to imagecontainer
CloudBlockBlob cloudblobnew = imgcontainer.GetBlockBlobReference(newblobname);
cloudblobnew.UploadFromFileAsync(newfile);
}
If your still have any problem, please feel free to let me know. Hope it helps you.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
1- Rename the old image name : for example 'xama_452_11_2018"
Due to the lack of API to rename the blob file on Azure, you could set newBlobName with the format you want and copy the source to the destination. Refer to this article.
2-Move it in a container "oldcontainer"
You could get the desctionation container's blob to copy the source. Refer to this one.
3- then save the new image in "imagecontainer"
Upload blob to the sourcecontainer. Refer to this article.
The whole codes are as below:
public static void RenameBlob(string containerName, string destContainer,string blobName,string newblobname)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer imgcontainer = cloudBlobClient.GetContainerReference(containerName);
string name = blobName.Split('.');
//rename blob
string newBlobName = name[0] + "_"+DateTime.Now.ToString("MM")+"_"+DateTime.Now.ToString("yyyy") + "." + name[1];
CloudBlobContainer oldcontainer = cloudBlobClient.GetContainerReference(destContainer);
if (!oldcontainer.Exists())
{
throw new Exception("Destination container does not exist.");
}
CloudBlockBlob blobCopy = oldcontainer.GetBlockBlobReference(newBlobName);
if (!blobCopy.Exists())
{
CloudBlockBlob blob = imgcontainer.GetBlockBlobReference(blobName);
if (blob.Exists())
{
//move blob to oldcontainer
blobCopy.StartCopy(blob);
blob.Delete();
}
}
//upload blob to imagecontainer
CloudBlockBlob cloudblobnew = imgcontainer.GetBlockBlobReference(newblobname);
cloudblobnew.UploadFromFileAsync(newfile);
}
If your still have any problem, please feel free to let me know. Hope it helps you.
add a comment |
up vote
0
down vote
accepted
1- Rename the old image name : for example 'xama_452_11_2018"
Due to the lack of API to rename the blob file on Azure, you could set newBlobName with the format you want and copy the source to the destination. Refer to this article.
2-Move it in a container "oldcontainer"
You could get the desctionation container's blob to copy the source. Refer to this one.
3- then save the new image in "imagecontainer"
Upload blob to the sourcecontainer. Refer to this article.
The whole codes are as below:
public static void RenameBlob(string containerName, string destContainer,string blobName,string newblobname)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer imgcontainer = cloudBlobClient.GetContainerReference(containerName);
string name = blobName.Split('.');
//rename blob
string newBlobName = name[0] + "_"+DateTime.Now.ToString("MM")+"_"+DateTime.Now.ToString("yyyy") + "." + name[1];
CloudBlobContainer oldcontainer = cloudBlobClient.GetContainerReference(destContainer);
if (!oldcontainer.Exists())
{
throw new Exception("Destination container does not exist.");
}
CloudBlockBlob blobCopy = oldcontainer.GetBlockBlobReference(newBlobName);
if (!blobCopy.Exists())
{
CloudBlockBlob blob = imgcontainer.GetBlockBlobReference(blobName);
if (blob.Exists())
{
//move blob to oldcontainer
blobCopy.StartCopy(blob);
blob.Delete();
}
}
//upload blob to imagecontainer
CloudBlockBlob cloudblobnew = imgcontainer.GetBlockBlobReference(newblobname);
cloudblobnew.UploadFromFileAsync(newfile);
}
If your still have any problem, please feel free to let me know. Hope it helps you.
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
1- Rename the old image name : for example 'xama_452_11_2018"
Due to the lack of API to rename the blob file on Azure, you could set newBlobName with the format you want and copy the source to the destination. Refer to this article.
2-Move it in a container "oldcontainer"
You could get the desctionation container's blob to copy the source. Refer to this one.
3- then save the new image in "imagecontainer"
Upload blob to the sourcecontainer. Refer to this article.
The whole codes are as below:
public static void RenameBlob(string containerName, string destContainer,string blobName,string newblobname)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer imgcontainer = cloudBlobClient.GetContainerReference(containerName);
string name = blobName.Split('.');
//rename blob
string newBlobName = name[0] + "_"+DateTime.Now.ToString("MM")+"_"+DateTime.Now.ToString("yyyy") + "." + name[1];
CloudBlobContainer oldcontainer = cloudBlobClient.GetContainerReference(destContainer);
if (!oldcontainer.Exists())
{
throw new Exception("Destination container does not exist.");
}
CloudBlockBlob blobCopy = oldcontainer.GetBlockBlobReference(newBlobName);
if (!blobCopy.Exists())
{
CloudBlockBlob blob = imgcontainer.GetBlockBlobReference(blobName);
if (blob.Exists())
{
//move blob to oldcontainer
blobCopy.StartCopy(blob);
blob.Delete();
}
}
//upload blob to imagecontainer
CloudBlockBlob cloudblobnew = imgcontainer.GetBlockBlobReference(newblobname);
cloudblobnew.UploadFromFileAsync(newfile);
}
If your still have any problem, please feel free to let me know. Hope it helps you.
1- Rename the old image name : for example 'xama_452_11_2018"
Due to the lack of API to rename the blob file on Azure, you could set newBlobName with the format you want and copy the source to the destination. Refer to this article.
2-Move it in a container "oldcontainer"
You could get the desctionation container's blob to copy the source. Refer to this one.
3- then save the new image in "imagecontainer"
Upload blob to the sourcecontainer. Refer to this article.
The whole codes are as below:
public static void RenameBlob(string containerName, string destContainer,string blobName,string newblobname)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer imgcontainer = cloudBlobClient.GetContainerReference(containerName);
string name = blobName.Split('.');
//rename blob
string newBlobName = name[0] + "_"+DateTime.Now.ToString("MM")+"_"+DateTime.Now.ToString("yyyy") + "." + name[1];
CloudBlobContainer oldcontainer = cloudBlobClient.GetContainerReference(destContainer);
if (!oldcontainer.Exists())
{
throw new Exception("Destination container does not exist.");
}
CloudBlockBlob blobCopy = oldcontainer.GetBlockBlobReference(newBlobName);
if (!blobCopy.Exists())
{
CloudBlockBlob blob = imgcontainer.GetBlockBlobReference(blobName);
if (blob.Exists())
{
//move blob to oldcontainer
blobCopy.StartCopy(blob);
blob.Delete();
}
}
//upload blob to imagecontainer
CloudBlockBlob cloudblobnew = imgcontainer.GetBlockBlobReference(newblobname);
cloudblobnew.UploadFromFileAsync(newfile);
}
If your still have any problem, please feel free to let me know. Hope it helps you.
answered Nov 12 at 5:48
Joey Cai
4,043129
4,043129
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247933%2frename-blob-then-save-new%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Possible duplicate of Azure Storage Blob Rename
– Jayendran
Nov 11 at 13:07
It it not the sae I want to rename the old image file , if you can help me
– kikis
Nov 11 at 15:24