Selaa lähdekoodia

Provide the mime type when creating a Blob (#999)

Lennart Grahl 5 vuotta sitten
vanhempi
commit
d55f743195
3 muutettua tiedostoa jossa 29 lisäystä ja 4 poistoa
  1. 6 1
      src/directives/mediabox.ts
  2. 8 1
      src/directives/message.ts
  3. 15 2
      src/directives/message_media.ts

+ 6 - 1
src/directives/mediabox.ts

@@ -54,7 +54,12 @@ export default [
                     }
                 };
                 this.save = () => {
-                    saveAs(new Blob([mediaboxService.data]), mediaboxService.filename || 'image.jpg');
+                    saveAs(
+                        new Blob([mediaboxService.data], {
+                            type: mediaboxService.mimetype,
+                        }),
+                        mediaboxService.filename || 'image.jpg'
+                    );
                 };
 
                 // Listen to Mediabox service events

+ 8 - 1
src/directives/message.ts

@@ -150,7 +150,14 @@ export default [
                                         case 'video':
                                         case 'file':
                                         case 'audio':
-                                            saveAs(new Blob([blobInfo.buffer]), blobInfo.filename);
+                                            const options = {type: blobInfo.mimetype};
+                                            saveAs(
+                                                new Blob(
+                                                    [blobInfo.buffer],
+                                                    options
+                                                ),
+                                                blobInfo.filename
+                                            );
                                             break;
                                         default:
                                             log.warn('Ignored download request for message type', this.message.type);

+ 15 - 2
src/directives/message_media.ts

@@ -239,6 +239,7 @@ export default [
                                     log.debug('Blob loaded');
                                     this.downloading = false;
                                     this.downloaded = true;
+                                    const options = {type: blobInfo.mimetype};
 
                                     switch (message.type) {
                                         case 'image':
@@ -251,7 +252,13 @@ export default [
                                             );
                                             break;
                                         case 'video':
-                                            saveAs(new Blob([blobInfo.buffer]), blobInfo.filename);
+                                            saveAs(
+                                                new Blob(
+                                                    [blobInfo.buffer],
+                                                    options
+                                                ),
+                                                blobInfo.filename
+                                            );
                                             break;
                                         case 'file':
                                             if (message.file.type === 'image/gif') {
@@ -261,7 +268,13 @@ export default [
                                                 // Hide thumbnail
                                                 this.showThumbnail = false;
                                             } else {
-                                                saveAs(new Blob([blobInfo.buffer]), blobInfo.filename);
+                                                saveAs(
+                                                    new Blob(
+                                                        [blobInfo.buffer],
+                                                        options
+                                                    ),
+                                                    blobInfo.filename
+                                                );
                                             }
                                             break;
                                         case 'audio':