public async Task <HttpResponseMessage> Get(HttpRequestMessage req, TraceWriter log)
        {
            var fileId = req.GetQueryNameValuePairs().Where(w => w.Key == "fileId").First().Value;

            if (string.IsNullOrWhiteSpace(fileId))
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest));
            }

            var savedFile = await _savedFileRepository.GetItemAsync(fileId);

            if (savedFile == null)
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest));
            }

            var mediaResponse = await _savedFileRepository.GetAttachmentMediaAsync(fileId, savedFile.attachmentId);

            if (mediaResponse == null)
            {
                req.CreateResponse(HttpStatusCode.NoContent);
            }

            var response = req.CreateResponse(HttpStatusCode.OK);

            response.Content = new StreamContent(mediaResponse.Media);
            response.Content.Headers.ContentType                 = new MediaTypeHeaderValue("application/octet-stream");
            response.Content.Headers.ContentDisposition          = new ContentDispositionHeaderValue("attachment");
            response.Content.Headers.ContentDisposition.FileName = savedFile.fileName;
            return(response);
        }
예제 #2
0
        public async Task <HttpResponseMessage> Get(HttpRequestMessage req, TraceWriter log)
        {
            var documentId = req.GetQueryNameValuePairs().Where(w => w.Key == "documentId").First().Value;
            var photoId    = req.GetQueryNameValuePairs().Where(w => w.Key == "photoId").First().Value;

            if (string.IsNullOrWhiteSpace(documentId) || string.IsNullOrWhiteSpace(photoId))
            {
                return(req.CreateResponse(HttpStatusCode.NotFound));
            }

            var mediaResponse = await _driverRepository.GetAttachmentMediaAsync(documentId, photoId);

            if (mediaResponse == null)
            {
                return(req.CreateResponse(HttpStatusCode.NotFound));
            }

            var response = req.CreateResponse(HttpStatusCode.OK);

            response.Content = new StreamContent(mediaResponse.Media);
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
            return(response);
        }