示例#1
0
        public ActionResult Upload(string title, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var mimeTypeExtension = new MimeTypeExtension();
                    MimeType mimeType = mimeTypeExtension.GetType(file.ContentType);

                    if (mimeType == MimeType.Photo)
                    {
                        var newPhoto = new Photo()
                        {
                            Id = file.FileName + Guid.NewGuid().ToString(),
                            FileName = file.FileName,
                            ContentType = file.ContentType,
                            Title = title,
                            DateAdded = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString(),
                            UploadedBy = User.Identity.Name
                        };

                        // Lätt till ett jobb för worker rolen som ska skapa en thumbnail
                        JobQueue jobQueue = new JobQueue();
                        jobQueue.AddJob(newPhoto.RowKey);

                        // Ladda upp till blob
                        var blobContainer = new BlobContainer("rawimages");
                        newPhoto.RawUri = blobContainer.UploadBlob(file.InputStream, newPhoto.RowKey, file.ContentType);

                        // Lägg till i tabellen
                        TableAccess tableAccess = new TableAccess("photoinformation");
                        tableAccess.Add(newPhoto);

                        ViewData["Success"] = "Your photo were uploaded successfully!";
                        return RedirectToAction("Index");
                    }
                    if (mimeType == MimeType.Document)
                    {
                        var newDocument = new Document()
                        {
                            Id = file.FileName + Guid.NewGuid().ToString(),
                            FileName = file.FileName,
                            ContentType = file.ContentType,
                            Title = title,
                            DateAdded = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString(),
                            ContentLength = file.ContentLength / 1024 + "kb",
                            UploadedBy = User.Identity.Name
                        };

                        // Ladda upp till blob
                        var blobContainer = new BlobContainer("documents");
                        newDocument.RawUri = blobContainer.UploadBlob(file.InputStream, newDocument.RowKey, file.ContentType);

                        // Lägg till i tabellen
                        TableAccess tableAccess = new TableAccess("documentinformation");
                        tableAccess.Add(newDocument);

                        return RedirectToAction("Index", "Document");
                    }
                    if (mimeType == MimeType.Video)
                    {
                        var newVideo = new Video()
                        {
                            Id = file.FileName + Guid.NewGuid().ToString(),
                            FileName = file.FileName,
                            ContentType = file.ContentType,
                            Title = title,
                            DateAdded = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString(),
                            UploadedBy = User.Identity.Name
                        };

                        // Ladda upp till blob
                        var blobContainer = new BlobContainer("videos");
                        newVideo.RawUri = blobContainer.UploadBlob(file.InputStream, newVideo.RowKey, file.ContentType);

                        // Lägg till i tabellen
                        TableAccess tableAccess = new TableAccess("videoinformation");
                        tableAccess.Add(newVideo);

                        return RedirectToAction("Index", "Video");
                    }
                    if (mimeType == MimeType.Audio)
                    {
                        var newAudio = new Audio()
                        {
                            Id = file.FileName + Guid.NewGuid().ToString(),
                            FileName = file.FileName,
                            ContentType = file.ContentType,
                            Title = title,
                            DateAdded = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString(),
                            UploadedBy = User.Identity.Name
                        };

                        // Ladda upp till blob
                        var blobContainer = new BlobContainer("audios");
                        newAudio.RawUri = blobContainer.UploadBlob(file.InputStream, newAudio.RowKey, file.ContentType);

                        // Lägg till i tabellen
                        TableAccess tableAccess = new TableAccess("audioinformation");
                        tableAccess.Add(newAudio);

                        return RedirectToAction("Index", "Audio");
                    }
                    if (mimeType == MimeType.NotAccepted)
                        ViewData["Error"] = "Unsupported content, try another! (maybe i´ve missed to add it as supported)";

                }
                catch (Exception ex)
                {
                    ViewData["Error"] = "Error: " + ex.Message;
                }
            }

            return View("Upload");
        }
示例#2
0
 public void Update(Photo photo)
 {
     TableOperation opp = TableOperation.Replace(photo);
     _table.Execute(opp);
 }