Skip to content

Commit c4402b8

Browse files
committed
fix: Pass existing mimetype as parameter from file
1 parent deb2cb7 commit c4402b8

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

src/lib/api/upload/file_tools.browser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ const readPart = (start: number, end: number, file): Promise<any> => {
154154
* @param {*} fileOrString
155155
* @returns {Promise<File>}
156156
*/
157-
export const getFile = (input: InputFile, sanitizeOptions?: SanitizeOptions): Promise<FsFile> => {
157+
export const getFile = (input: InputFile, sanitizeOptions?: SanitizeOptions, mimetype?: string): Promise<FsFile> => {
158158
let filename;
159159
let file: Blob;
160160

@@ -186,7 +186,7 @@ export const getFile = (input: InputFile, sanitizeOptions?: SanitizeOptions): Pr
186186
{
187187
name: filename,
188188
size: file.size,
189-
type: mime,
189+
type: mimetype || mime,
190190
slice: res.slice,
191191
release: res.release,
192192
},

src/lib/api/upload/file_tools.node.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const isFileBase = (input: InputFile): input is string => {
6363
* @param {*} inputFile
6464
* @returns {Promise<File>}
6565
*/
66-
export const getFile = async(input: InputFile, sanitizeOptions?: SanitizeOptions): Promise<FsFile> => {
66+
export const getFile = async(input: InputFile, sanitizeOptions?: SanitizeOptions, mimetype?: string): Promise<FsFile> => {
6767
let filename;
6868

6969
if (isFileNamed(input)) {
@@ -88,7 +88,7 @@ export const getFile = async(input: InputFile, sanitizeOptions?: SanitizeOptions
8888
{
8989
name: filename,
9090
size: buffer.byteLength,
91-
type: mime,
91+
type: mimetype || mime,
9292
slice: (start, end) => Promise.resolve(buffer.slice(start, end)),
9393
},
9494
sanitizeOptions
@@ -114,7 +114,7 @@ export const getFile = async(input: InputFile, sanitizeOptions?: SanitizeOptions
114114
{
115115
name: filename,
116116
size: input.byteLength,
117-
type: mime,
117+
type: mimetype || mime,
118118
// @ts-ignore
119119
slice: (start, end) => Promise.resolve(input.slice(start, end)),
120120
},

src/lib/api/upload/upload.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ export class Upload extends EventEmitter {
203203
* @returns {Promise<any>}
204204
* @memberof Upload
205205
*/
206-
async upload(input: InputFile, altText?: string): Promise<any> {
206+
async upload(input: InputFile, altText?: string, mimetype?: string): Promise<any> {
207207

208-
const f = await getFile(input, this.sanitizerOptions);
208+
const f = await getFile(input, this.sanitizerOptions, mimetype);
209209
f.customName = this.overrideFileName;
210210
if (altText) {
211211
f.alt = altText;

src/lib/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ export class Client extends EventEmitter {
445445
*
446446
* @returns {Promise}
447447
*/
448-
upload(file: InputFile, options?: UploadOptions, storeOptions?: StoreUploadOptions, token?: any, security?: Security) {
448+
upload(file: InputFile, options?: UploadOptions, storeOptions?: StoreUploadOptions, token?: any, security?: Security, mimetype?: string) {
449449
let upload = new Upload(options, storeOptions);
450450
upload.setSession(this.session);
451451

@@ -474,7 +474,7 @@ export class Client extends EventEmitter {
474474
this.emit('upload.error', e);
475475
});
476476

477-
return upload.upload(file, options && options.altText);
477+
return upload.upload(file, options && options.altText, mimetype);
478478
}
479479

480480
/**

0 commit comments

Comments
 (0)