public HttpResponseMessage GetRingtones()
        {
            BlobStorageService blobStorage = new BlobStorageService();

            // Retrieve storage account from connection string.
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));

            // Create the blob client.
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

            // Retrieve a reference to a container.
            CloudBlobContainer blobContainer = blobClient.GetContainerReference("ringtones");



            // Loop over items within the container and output the length and URI.
            foreach (IListBlobItem item in blobContainer.ListBlobs(null, false))
            {
                if (item.GetType() == typeof(CloudBlockBlob))
                {
                    CloudBlockBlob blob = (CloudBlockBlob)item;

                    Console.WriteLine("Block blob of length {0}: {1}", blob.Properties.Length, blob.Uri);

                }
                else if (item.GetType() == typeof(CloudPageBlob))
                {
                    CloudPageBlob pageBlob = (CloudPageBlob)item;

                    Console.WriteLine("Page blob of length {0}: {1}", pageBlob.Properties.Length, pageBlob.Uri);

                }
                else if (item.GetType() == typeof(CloudBlobDirectory))
                {
                    CloudBlobDirectory directory = (CloudBlobDirectory)item;

                    Console.WriteLine("Directory: {0}", directory.Uri);
                }
            }





            // Create the container if it doesn't already exist.
            blobContainer.CreateIfNotExists();

            var list = blobContainer.ListBlobs();

            List<string> blobNames = list.OfType<CloudBlockBlob>().Select(b => b.Name).ToList();

            var returnData = blobNames;
            return Request.CreateResponse(HttpStatusCode.OK, returnData);
        }
Ejemplo n.º 2
0
        public ContentResult GetSasUrl()
        {
            BlobStorageService blobStorage = new BlobStorageService();

            // Retrieve storage account from connection string.
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));

            // Create the blob client.
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

            // Retrieve a reference to a container.
            CloudBlobContainer blobContainer = blobClient.GetContainerReference("ringtones");

            // Create the container if it doesn't already exist.
            blobContainer.CreateIfNotExists();


            return Content(GetContainerSasUri(blobContainer));

        }
Ejemplo n.º 3
0
        public ActionResult UploadReport(HttpPostedFileBase files)
        {
            int ReportTypeID = Convert.ToInt32(HttpContext.Request.Form["ReportType"]);

            HttpPostedFileBase uploadedFile = files;
            try
            {
                AjaxResult res = new AjaxResult();
                if (uploadedFile.ContentLength > 0)
                {
                    BlobStorageService blobStorage = new BlobStorageService();

                    // Retrieve storage account from connection string.
                    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));

                    // Create the blob client.
                    CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

                    // Retrieve a reference to a container.
                    CloudBlobContainer blobContainer = blobClient.GetContainerReference("ringtones");

                    // Create the container if it doesn't already exist.
                    blobContainer.CreateIfNotExists();

                    //CloudBlobContainer blobContainer = blobStorage.GetCloudBlobContainer();


                    //string filename = blobStorage.GetReadData("M0JJ0v8.png");
                    string UploadedFileName = uploadedFile.FileName;
                    CloudBlockBlob blob = blobContainer.GetBlockBlobReference(UploadedFileName);
                    blob.UploadFromStream(uploadedFile.InputStream);

                    //string page = System.Web.Configuration.WebConfigurationManager.AppSettings["FileAPIUrl"].ToString();


                    //using (HttpClient client = new HttpClient())
                    //{
                    //    client.BaseAddress = new Uri(page);

                    //    client.Timeout = TimeSpan.FromHours(1);

                    //    var result = client.PostAsync(page + "?UploadedFileName=" + UploadedFileName + "&FileType=" + ReportTypeID.ToString(), null);

                    //    result.Wait();

                    //    string resultContent = result.Result.Content.ReadAsStringAsync().Result;
                    //    if (String.IsNullOrEmpty(resultContent))
                    //    {
                    //        res.isSuccessfull = true;
                    //        res.Data = "File Uploaded Successfully";
                    //    }
                    //    else
                    //    {
                    //        res.isSuccessfull = false;
                    //        res.ErrorMessage = resultContent;
                    //    }
                    //}

                    return Json(res);
                }
                else
                {
                    return Json(new AjaxResult { isSuccessfull = false, Data = "", ErrorMessage = "Empty File" });
                }
            }
            catch (Exception ex)
            {
                return Json(new AjaxResult { isSuccessfull = false, Data = "", ErrorMessage = ex.InnerException.Message });
            }
        }