public ActionResult ThumbnailUpload() { try { UploadedFile file = RetrieveFileFromRequest(); if (file.FileName != null) { string filename = Path.GetFileName(file.FileName); if (filename != null) { var args = new RIAPP.DataService.ServiceArgs(new Serializer(), this.User); RIAppDemoService svc = new RIAppDemoService(args); using (svc) { svc.SaveThumbnail(file.DataID, file.FileName, file.Contents); } } } return new HttpStatusCodeResult(200); } catch (Exception) { return new HttpStatusCodeResult(400); } }
public HttpResponseMessage UploadThumbnail(HttpRequestMessage request) { try { UploadedFile file = RetrieveFileFromRequest(request); if (file.FileName != null) { string filename = Path.GetFileName(file.FileName); if (filename != null) { var args = new RIAPP.DataService.ServiceArgs(new Serializer(), this.User); RIAppDemoService svc = new RIAppDemoService(args); using (svc) { svc.SaveThumbnail2(file.DataID, file.FileName, file.Content.CopyToAsync); } } } return Request.CreateResponse(HttpStatusCode.OK); } catch (Exception ex) { var response = Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message); throw new HttpResponseException(response); } }
public ActionResult ThumbnailDownload(int id) { try { RIAppDemoService svc = new RIAppDemoService(this.User); using (svc) { MemoryStream stream = new MemoryStream(); string fileName = svc.GetThumbnail(id, stream); if (string.IsNullOrEmpty(fileName)) return new HttpStatusCodeResult(400); stream.Position = 0; var res = new FileStreamResult(stream, System.Net.Mime.MediaTypeNames.Image.Jpeg); res.FileDownloadName = fileName; return res; } } catch (Exception ex) { return new HttpStatusCodeResult(404); } }
public HttpResponseMessage DownloadThumbnail(HttpRequestMessage request, string id) { try { var args = new RIAPP.DataService.ServiceArgs(new Serializer(), this.User); RIAppDemoService svc = new RIAppDemoService(args); using (svc) { MemoryStream stream = new MemoryStream(); string fileName = svc.GetThumbnail(int.Parse(id), stream); if (string.IsNullOrEmpty(fileName)) return Request.CreateResponse(HttpStatusCode.NotFound); stream.Position = 0; HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); result.Content = new StreamContent(stream); result.Content.Headers.ContentType = new MediaTypeHeaderValue(System.Net.Mime.MediaTypeNames.Image.Jpeg); result.Content.Headers.Add("Content-Disposition", new string[]{string.Format("attachment; filename=\"{0}\"", fileName) }); return result; } } catch (Exception ex) { var response = Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message); throw new HttpResponseException(response); } }