32 lines
788 B
TypeScript
32 lines
788 B
TypeScript
import { post } from './request';
|
|
|
|
export interface AttachmentUploadRequest {
|
|
file: File;
|
|
sourceType: string;
|
|
sourceId?: string;
|
|
}
|
|
|
|
export interface AttachmentResponse {
|
|
id: string;
|
|
sourceType: string;
|
|
sourceId?: string | null;
|
|
originalName: string;
|
|
fileName: string;
|
|
fileSuffix?: string | null;
|
|
contentType?: string | null;
|
|
fileSize: number;
|
|
storageType: string;
|
|
fileUrl?: string | null;
|
|
remark?: string | null;
|
|
}
|
|
|
|
export function uploadAttachment(data: AttachmentUploadRequest) {
|
|
const formData = new FormData();
|
|
formData.append('file', data.file);
|
|
formData.append('sourceType', data.sourceType);
|
|
if (data.sourceId) {
|
|
formData.append('sourceId', data.sourceId);
|
|
}
|
|
return post<AttachmentResponse, FormData>('/attachments/upload', formData);
|
|
}
|