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










share|improve this question

















  • 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














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










share|improve this question

















  • 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












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










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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












  • 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












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.






share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    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

























    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.






    share|improve this answer
























      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.






      share|improve this answer






















        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 12 at 5:48









        Joey Cai

        4,065129




        4,065129



























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            Node.js Script on GitHub Pages or Amazon S3

            Museum of Modern and Contemporary Art of Trento and Rovereto