1818
1919import static com .google .common .base .Preconditions .checkNotNull ;
2020import static com .google .common .util .concurrent .Futures .getUnchecked ;
21- import static javax .activation .FileTypeMap .getDefaultFileTypeMap ;
2221
2322import java .io .IOException ;
23+ import java .net .FileNameMap ;
24+ import java .net .URLConnection ;
2425import java .nio .file .Files ;
2526import java .nio .file .Paths ;
2627
2728import org .springframework .beans .factory .annotation .Autowired ;
2829import org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
2930import org .springframework .stereotype .Component ;
3031
32+ import com .google .common .annotations .VisibleForTesting ;
33+
3134import com .linecorp .bot .cli .arguments .Arguments ;
3235import com .linecorp .bot .client .LineMessagingClient ;
3336import com .linecorp .bot .model .response .BotApiResponse ;
4043@ ConditionalOnProperty (name = "command" , havingValue = "richmenu-upload" )
4144@ AllArgsConstructor (onConstructor = @ __ (@ Autowired ))
4245public class RichMenuImageUploadCommand implements CliCommand {
46+ private static final FileNameMap FILE_NAME_MAP = URLConnection .getFileNameMap ();
47+
4348 private LineMessagingClient lineMessagingClient ;
4449 private Arguments arguments ;
4550
4651 @ Override
4752 public void execute () throws IOException {
4853 final String richMenuId = checkNotNull (arguments .getRichMenuId (), "--rich-menu-id= is not set." );
4954 final String image = checkNotNull (arguments .getImage (), "--image= is not set." );
50- final String contentType = checkNotNull (getDefaultFileTypeMap (). getContentType (image ),
55+ final String contentType = checkNotNull (resolveContentTypeForFileName (image ),
5156 "Can't assume Content-Type" );
5257 log .info ("Content-Type: {}" , contentType );
5358
@@ -57,4 +62,9 @@ public void execute() throws IOException {
5762
5863 log .info ("Request Successfully finished. {}" , botApiResponse );
5964 }
65+
66+ @ VisibleForTesting
67+ static String resolveContentTypeForFileName (final String fileName ) {
68+ return FILE_NAME_MAP .getContentTypeFor (fileName );
69+ }
6070}
0 commit comments