public object UploadBiblo(string comment) { var file = HttpContext.Current.Request.Files[0];//we have the file... var uniquefileName = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName); //string ftpAddress = @"197.242.150.135"; // ConfigurationManager.AppSettings.Get("CloudStorageContainerReference") //string username = "******"; // ConfigurationManager.AppSettings.Get("CloudStorageContainerReference") //string password = "******"; // ConfigurationManager.AppSettings.Get("CloudStorageContainerReference") var postedFile = HttpContext.Current.Request.Files[0]; var filePath = HttpContext.Current.Server.MapPath("~/images/" + postedFile.FileName); var rootPath = "https://geared4it.net/images/"; var nextFileId = cugDB.BibloUploads.OrderByDescending(mf => mf.Id).FirstOrDefault().Id + 1; BibloUpload f = new BibloUpload { Id = nextFileId, fName = postedFile.FileName,// uniquefileName,// file.FileName; // f.fNamePath = rootPath + uniquefileName; fDescription = comment, fTitle = comment, fType = Path.GetExtension(file.FileName) }; cugDB.BibloUploads.Add(f); cugDB.SaveChanges(); postedFile.SaveAs(filePath); return(postedFile.FileName + " filePath: " + filePath); }
// public async Task<IHttpActionResult> Upload(string id) public object UploadBibloAzure(string comment) { var file = HttpContext.Current.Request.Files[0];//we have the file... if (HttpContext.Current.Request.Files.Count > 0) { var accountName = "cugonlinestorage";// ConfigurationManager.AppSettings["cugonlinestorage"]; var accountKey = "V9xb1fQUAt/90BtzG5+1o1rlcKMP1cY83PGONzzNu5bxXW4DZ09c+/yLW4ixbdnLaNcRpkrJX7OqFALKet0FcQ=="; CloudStorageAccount storageAccount = new CloudStorageAccount(new StorageCredentials(accountName, accountKey), true); var storageClient = storageAccount.CreateCloudBlobClient(); var storageContainer = storageClient.GetContainerReference(ConfigurationManager.AppSettings.Get("CloudStorageContainerReference")); storageContainer.CreateIfNotExists(); for (int fileNum = 0; fileNum < HttpContext.Current.Request.Files.Count; fileNum++) { var uniquefileName = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName); if (HttpContext.Current.Request.Files[fileNum] != null && HttpContext.Current.Request.Files[fileNum].ContentLength > 0) { //do upload r CloudBlockBlob azureBlockBlob = storageContainer.GetBlockBlobReference(uniquefileName); azureBlockBlob.UploadFromStream(HttpContext.Current.Request.Files[fileNum].InputStream); try//saving to database... { var nextFileId = cugDB.BibloUploads.OrderByDescending(mf => mf.Id).FirstOrDefault().Id + 1; BibloUpload f = new BibloUpload { Id = nextFileId, fName = uniquefileName, // file.FileName; // f.fNamePath = rootPath + uniquefileName; fDescription = comment, fType = Path.GetExtension(file.FileName) }; cugDB.BibloUploads.Add(f); cugDB.SaveChanges(); } catch (Exception ex) { throw ex; } } } } return(Ok()); }