comparison Core/FileStorage/StorageAccessor.cpp @ 1772:53e045b5a8ec

MIME content type can be associated to custom attachments (cf. "UserContentType")
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 12 Nov 2015 14:36:27 +0100
parents 55d52567bebb
children b1291df2f780
comparison
equal deleted inserted replaced
1771:8790488ae98b 1772:53e045b5a8ec
139 } 139 }
140 } 140 }
141 141
142 142
143 void StorageAccessor::SetupSender(BufferHttpSender& sender, 143 void StorageAccessor::SetupSender(BufferHttpSender& sender,
144 const FileInfo& info) 144 const FileInfo& info,
145 const std::string& mime)
145 { 146 {
146 area_.Read(sender.GetBuffer(), info.GetUuid(), info.GetContentType()); 147 area_.Read(sender.GetBuffer(), info.GetUuid(), info.GetContentType());
147 sender.SetContentType(GetMimeType(info.GetContentType())); 148 sender.SetContentType(mime);
148 sender.SetContentFilename(info.GetUuid() + std::string(GetFileExtension(info.GetContentType()))); 149
150 const char* extension;
151 switch (info.GetContentType())
152 {
153 case FileContentType_Dicom:
154 extension = ".dcm";
155 break;
156
157 case FileContentType_DicomAsJson:
158 extension = ".json";
159 break;
160
161 default:
162 // Non-standard content type
163 extension = "";
164 }
165
166 sender.SetContentFilename(info.GetUuid() + std::string(extension));
149 } 167 }
150 168
151 169
152 void StorageAccessor::AnswerFile(HttpOutput& output, 170 void StorageAccessor::AnswerFile(HttpOutput& output,
153 const FileInfo& info) 171 const FileInfo& info,
172 const std::string& mime)
154 { 173 {
155 BufferHttpSender sender; 174 BufferHttpSender sender;
156 SetupSender(sender, info); 175 SetupSender(sender, info, mime);
157 176
158 HttpStreamTranscoder transcoder(sender, info.GetCompressionType()); 177 HttpStreamTranscoder transcoder(sender, info.GetCompressionType());
159 output.Answer(transcoder); 178 output.Answer(transcoder);
160 } 179 }
161 180
162 181
163 void StorageAccessor::AnswerFile(RestApiOutput& output, 182 void StorageAccessor::AnswerFile(RestApiOutput& output,
164 const FileInfo& info) 183 const FileInfo& info,
184 const std::string& mime)
165 { 185 {
166 BufferHttpSender sender; 186 BufferHttpSender sender;
167 SetupSender(sender, info); 187 SetupSender(sender, info, mime);
168 188
169 HttpStreamTranscoder transcoder(sender, info.GetCompressionType()); 189 HttpStreamTranscoder transcoder(sender, info.GetCompressionType());
170 output.AnswerStream(transcoder); 190 output.AnswerStream(transcoder);
171 } 191 }
172 } 192 }