👕
This commit is contained in:
@ -2,22 +2,15 @@
|
|||||||
import { client } from './ApiClient';
|
import { client } from './ApiClient';
|
||||||
import invariant from 'invariant';
|
import invariant from 'invariant';
|
||||||
|
|
||||||
type File = {
|
|
||||||
blob: boolean,
|
|
||||||
type: string,
|
|
||||||
size: number,
|
|
||||||
name?: string,
|
|
||||||
file: string,
|
|
||||||
};
|
|
||||||
|
|
||||||
type Options = {
|
type Options = {
|
||||||
name?: string,
|
name?: string,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const uploadFile = async (file: File | Blob, option?: Options) => {
|
export const uploadFile = async (
|
||||||
// $FlowFixMe Blob makes life hard
|
file: File | Blob,
|
||||||
const filename = (option && option.name) || file.name;
|
option?: Options = { name: '' }
|
||||||
|
) => {
|
||||||
|
const filename = file instanceof File ? file.name : option.name;
|
||||||
const response = await client.post('/user.s3Upload', {
|
const response = await client.post('/user.s3Upload', {
|
||||||
kind: file.type,
|
kind: file.type,
|
||||||
size: file.size,
|
size: file.size,
|
||||||
@ -38,7 +31,6 @@ export const uploadFile = async (file: File | Blob, option?: Options) => {
|
|||||||
// $FlowFixMe
|
// $FlowFixMe
|
||||||
formData.append('file', file.file);
|
formData.append('file', file.file);
|
||||||
} else {
|
} else {
|
||||||
// $FlowFixMe
|
|
||||||
formData.append('file', file);
|
formData.append('file', file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user