Cloudservie automatically uploads content from localstroage to blobs via wad

Source: Internet
Author: User
Tags button type extract zip file

To develop a cloud service program, if you use the local stroage to store our temporarily generated logs or files and upload them automatically to the Blob, you can do so through wad, as follows:

1. Configure Webrole to turn on the local stroage feature:

2. Modify the Wadcfgx file to add the DataSources attribute:

3. Add the code uploaded to the local storage:

Index.cshtml

@{Viewbag.title="Home Page";}<divclass="Jumbotron"> class=" Lead">asp.net isA free web framework forBuilding great Web sites and Web applicationsusingHTML, CSS and javascript.</p> <p><a href="http://asp.net" class="btn btn-primary Btn-lg">learn more &raquo;</a></p></div><divclass="Row"> <divclass="col-md-12">@using (Html.BeginForm ("Uploadzipfile","Home", FormMethod.Post,New{enctype ="Multipart/form-data" }))        {            <divclass="Form-group"> <label for="ZipFile">zip file</label> <input type="file"Id="ZipFile"Name="ZipFile"> </div> <button type="Submit" class="btn Btn-default">Submit</button>        }    </div></div>

The corresponding HomeController.cs implementations are as follows:

         Publicactionresult uploadzipfile (httppostedfilebase zipfile) {varLocalresource = Roleenvironment.getlocalresource ("Zipfiles"); //Save zip file.            varLocalzipfilepath =Path.Combine (Localresource.rootpath, zipfile.filename);            Zipfile.saveas (Localzipfilepath); //Extract zip file to a random folder.            varLocalextractedpath =Path.Combine (Localresource.rootpath, Guid.NewGuid ().            ToString ());            Directory.CreateDirectory (Localextractedpath);            System.IO.Compression.ZipFile.ExtractToDirectory (Localzipfilepath, Localextractedpath); //Upload everything to blob storage.            foreach(varFileinchDirectory.GetFiles (Localextractedpath,"*", Searchoption.alldirectories)) {                //Upload to blob storage.            }            returnRedirecttoaction ("Index"); }

The path to get the local Storege is: var localresource = Roleenvironment.getlocalresource ("Zipfiles");

3. I have done a local test, through the code upload to the settings of the local storage, through the RDP login instance, you will see the file already exists, the path is the c:\resources\directory\{deployment ID}. Webrole1.zipfiles

4. Once the designated local storage has the content, the corresponding storage account will generate the container Wad-testcustom (this is also the name of their own settings), the log automatically uploaded successfully, you will see the corresponding storage account container, upload the previously tested files:

For details, refer to: http://blogs.msdn.com/b/davidhardin/archive/2011/03/31/ Configuring-diagnostics-wadcfg-to-capture-custom-log-files.aspx

About the local Storage, even if not tick "clean on role Recycle", when the node failover, if some of the logs have not been stored in time to the BLOB, we will still lose them, specifically, you can refer to:

http://justazure.com/microsoft-azure-cloud-services-part-3-service-package/

Cloudservie automatically uploads content from localstroage to blobs via wad

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.