Exemple #1
0
        public JsonResult GetUploaded(int id = 1)
        {
            VMFileUpload result = new VMFileUpload();

            result.files = new List <UploadedFile>();
            var tmpFiles = this.serviceTempFile.GetByProjectId(id, CurrentUser);

            foreach (var file in tmpFiles)
            {
                UploadedFile f = new UploadedFile()
                {
                    name = file.Name,
                    size = file.Size,
                    //url = Url.Action("GetTempFile", new { id = tmpFile.Id }),
                    //thumbnailUrl = "http//:www.google.com/picture1.jpg",
                    deleteUrl  = Url.Action("DeleteTempFile", new { id = file.Id }),
                    deleteType = "POST"
                };
                result.files.Add(f);
            }


            return(new JsonResult()
            {
                Data = result, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Exemple #2
0
        public JsonResult UploadAvatar(IEnumerable <HttpPostedFileBase> files, int userId)
        {//TODO Rework (fusion with UploadArtword)
            VMFileUpload result = new VMFileUpload();

            result.files = new List <UploadedFile>();
            if (files != null)
            {
                // only take the first one
                foreach (var baseFile in files)
                {
                    string thumbnailUrl = this.serviceThumbnail.StoreTemporaryAvatar(userId, baseFile.InputStream);
                    if (!String.IsNullOrEmpty(thumbnailUrl))
                    {
                        UploadedFile f = new UploadedFile()
                        {
                            name         = thumbnailUrl,
                            size         = baseFile.ContentLength,
                            thumbnailUrl = thumbnailUrl,
                            deleteUrl    = "TODO",
                            deleteType   = "POST"
                        };
                        result.files.Add(f);
                    }
                    break;
                }
            }

            return(new JsonResult()
            {
                Data = result
            });
        }
Exemple #3
0
        public JsonResult UploadArtwork(IEnumerable <HttpPostedFileBase> files, int projectId)
        {
            this.serviceLog.LogMessage("FileCOntroller", "UploadArtwork " + projectId);
            VMFileUpload result = new VMFileUpload();

            result.files = new List <UploadedFile>();
            if (files != null)
            {
                // only take the first one
                foreach (var baseFile in files)
                {
                    string thumbnailUrl = this.serviceThumbnail.StoreTemporaryProjectArtwork(projectId, baseFile.InputStream);
                    if (!String.IsNullOrEmpty(thumbnailUrl))
                    {
                        UploadedFile f = new UploadedFile()
                        {
                            name         = thumbnailUrl,
                            size         = baseFile.ContentLength,
                            thumbnailUrl = thumbnailUrl,
                            deleteUrl    = "TODO",
                            deleteType   = "POST"
                        };
                        result.files.Add(f);
                    }
                    break;
                }
            }

            return(new JsonResult()
            {
                Data = result
            });
        }
Exemple #4
0
        public JsonResult Upload(IEnumerable <HttpPostedFileBase> files, int id, int cloudStorage)
        {
            string log = "Upload file to " + id + " into " + cloudStorage;

            log += files != null ? "count = " + files.Count() : string.Empty;
            this.serviceLog.LogMessage("FileController", log);

            VMFileUpload result = new VMFileUpload();

            result.files = new List <UploadedFile>();
            foreach (var baseFile in files)
            {
                TempUploadedFile tmpFile = new TempUploadedFile();

                using (var binaryReader = new BinaryReader(baseFile.InputStream))
                {
                    tmpFile.Data = binaryReader.ReadBytes(baseFile.ContentLength);
                }
                tmpFile.Name             = baseFile.FileName;
                tmpFile.ProjectId        = id;
                tmpFile.Size             = tmpFile.Data.Length;
                tmpFile.AuthCredentialId = cloudStorage;

                tmpFile.Id = this.serviceTempFile.Create(tmpFile, CurrentUser);
                UploadedFile f = new UploadedFile()
                {
                    name = tmpFile.Name,
                    size = tmpFile.Size,
                    //url = Url.Action("GetTempFile", new { id = tmpFile.Id }),
                    //thumbnailUrl = "http//:www.google.com/picture1.jpg",
                    deleteUrl  = Url.Action("DeleteTempFile", new { id = tmpFile.Id }),
                    deleteType = "POST"
                };
                result.files.Add(f);
            }



            return(new JsonResult()
            {
                Data = result
            });
        }