|
@@ -5,6 +5,11 @@ using System.Linq;
|
|
|
using System.Net.Http.Headers;
|
|
|
using System.Threading.Tasks;
|
|
|
using HaBookCms.AzureBlobStorageTest.Models;
|
|
|
+using HaBookCms.AzureStorage.AzureBlob.Container;
|
|
|
+using HaBookCms.AzureStorage.AzureBlob.Implements;
|
|
|
+using HaBookCms.AzureStorage.AzureBlob.Interfaces;
|
|
|
+using HaBookCms.AzureStorage.AzureBlob.Models;
|
|
|
+using HaBookCms.AzureStorage.AzureTable.Interfaces;
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using Microsoft.WindowsAzure.Storage;
|
|
@@ -16,6 +21,14 @@ namespace HaBookCms.AzureBlobStorageTest.Controllers
|
|
|
[ApiController]
|
|
|
public class ValuesController : ControllerBase
|
|
|
{
|
|
|
+ public IAzureBlobDBRepository _azureBlobDBRepository;
|
|
|
+ public IAzureTableDBRepository _azureTableDBRepository;
|
|
|
+ public ValuesController(IAzureBlobDBRepository azureBlobDBRepository, IAzureTableDBRepository azureTableDBRepository) {
|
|
|
+ _azureBlobDBRepository = azureBlobDBRepository;
|
|
|
+ _azureTableDBRepository = azureTableDBRepository;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
// GET api/values
|
|
|
[HttpGet]
|
|
|
public ActionResult<IEnumerable<string>> Get()
|
|
@@ -65,20 +78,23 @@ namespace HaBookCms.AzureBlobStorageTest.Controllers
|
|
|
[HttpPost("Upload")]
|
|
|
//[Produces("application/json")]
|
|
|
//[Consumes("application/json", "multipart/form-data")]//此处为新增
|
|
|
- public async Task<IActionResult> Upload(IFormFile[] file )
|
|
|
+ public async Task<List<AzureBlobModel>> Upload(IFormFile[] file )
|
|
|
{
|
|
|
- var storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=teammodelstorage;AccountKey=Yq7D4dE6cFuer2d2UZIccTA/i0c3sJ/6ITc8tNOyW+K5f+/lWw9GCos3Mxhj47PyWQgDL8YbVD63B9XcGtrMxQ==;EndpointSuffix=core.chinacloudapi.cn");
|
|
|
- var blobClient = storageAccount.CreateCloudBlobClient();
|
|
|
- var container = blobClient.GetContainerReference("staticcontent");
|
|
|
- //var file = picture.File;
|
|
|
- foreach (IFormFile f in file) {
|
|
|
- var parsedContentDisposition =
|
|
|
- ContentDispositionHeaderValue.Parse(f.ContentDisposition);
|
|
|
- var filename = Path.Combine(parsedContentDisposition.FileName.Trim('"'));
|
|
|
- var blockBlob = container.GetBlockBlobReference(filename+Guid.NewGuid());
|
|
|
- await blockBlob.UploadFromStreamAsync(f.OpenReadStream());
|
|
|
- }
|
|
|
- return Ok();
|
|
|
+
|
|
|
+ //var storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=teammodelstorage;AccountKey=Yq7D4dE6cFuer2d2UZIccTA/i0c3sJ/6ITc8tNOyW+K5f+/lWw9GCos3Mxhj47PyWQgDL8YbVD63B9XcGtrMxQ==;EndpointSuffix=core.chinacloudapi.cn");
|
|
|
+ //var blobClient = storageAccount.CreateCloudBlobClient();
|
|
|
+ //var container = blobClient.GetContainerReference("staticcontent");
|
|
|
+ ////var file = picture.File;
|
|
|
+ //foreach (IFormFile f in file) {
|
|
|
+ // var parsedContentDisposition =
|
|
|
+ // ContentDispositionHeaderValue.Parse(f.ContentDisposition);
|
|
|
+ // var filename = Path.Combine(parsedContentDisposition.FileName.Trim('"'));
|
|
|
+ // var blockBlob = container.GetBlockBlobReference(filename+Guid.NewGuid());
|
|
|
+ // await blockBlob.UploadFromStreamAsync(f.OpenReadStream());
|
|
|
+ //}
|
|
|
+ List<AzureBlobModel> blobModels= _azureBlobDBRepository.UploadFiles(file, new FileContainer()).Result.ToList<AzureBlobModel>();
|
|
|
+ await _azureTableDBRepository.SaveAll<AzureBlobModel>(blobModels);
|
|
|
+ return blobModels;
|
|
|
}
|
|
|
[HttpGet("Download")]
|
|
|
//[Produces("application/json")]
|