1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import JoditEditor from 'jodit-react';
<JoditEditor ref={editor}
config={
{
height: 540,
disabled: !isEditable,
events: {
afterOpenPasteDialog: (
dialog,
msg,
title,
callback,
) => {
dialog.close();
callback();
},
},
uploader: {
url: 'http://localhost:8080/api/assets/uploadFile',
prepareData: function (data) {
data.append('folder', folder);
data.delete('path');
data.delete('source');
},
isSuccess: function (resp) {
setContent(
content.concat(
'<img src='path' alt="logo"/>',
),
);
},
},
} as any
}
value={content || ''}
onBlur={newContent => {
setContent(newContent);
}}
onChange={newContent => {}}
/>
<buttontype='button'
style={{ transition: 'all .15s ease' }}
onClick={() => {
const regex = /(style=".+?")/gm;
const subst = '';
const result = content.replace(regex, subst);
onUpdate && onUpdate(result);
}}
>
Upload
</button>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import Html from 'react-pdf-html';
const stylesheet = {
body: {
fontSize: '8px',
},
p: {
margin: 0,
fontSize: '12px',
},
table: {
border: '1px solid !important',
marginTop: 4,
marginBottom: 4,
},
td: {
padding: 2,
},
strong: {
fontFamily: 'IBMPlexSans',
fontWeight: 'bold',
},
em: {
fontFamily: 'IBMPlexSans',
fontStyle: 'italic',
},
img: {
width: 200,
height: 200,
},
};
const html = content => '
<html>
<body>
content
</body>
</html>
';
<Html stylesheet={stylesheet} key={index}>
{html(JSON.parse(item.result).result)}
</Html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// main.ts
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { express as voyagerMiddleware } from 'graphql-voyager/middleware';
import { graphqlUploadExpress } from 'graphql-upload';
import * as formData from 'express-form-data';
const app = await NestFactory.create(AppModule, {
bufferLogs: true,
});
app.use('/voyager', voyagerMiddleware({ endpointUrl: '/graphql' }));
app.use(
'/graphql',
graphqlUploadExpress({ maxFileSize: 10000000, maxFiles: 10 }),
);
// assets.controller.ts
@Post('uploadFile')
uploadFile(
@UploadedFiles() files: Array<Express.Multer.File>,
@Body() createAssetDto: CreateAssetDto,
) {
return this.assetsService.uploadFile(files, createAssetDto);
}
// assets.service.ts
async uploadFile(files: any, body: CreateAssetDto) {
try {
const file = files.files[0];
const storage = StorageClient.getStorage();
const blobClient = storage.getContainerClient(body?.folder);
const fileName = name;
const blobOptions = {
blobHTTPHeaders: { blobContentType: 'image/jpeg' },
};
await blobClient
.getBlockBlobClient(fileName)
.uploadFile(file?.path, blobOptions);
return {
statusCode: 200,
data: {
data: blobClient?.url + '/' + fileName,
settings: {
success: 1,
message: 'File upload successfully.',
},
},
status: 'success',
};
} catch (error) {
return {
statusCode: 400,
body: {
status: 'error',
message: error.message,
},
};
}
}
export class StorageClient {
static getStorage(): any {
return BlobServiceClient.fromConnectionString(
'connection string',
);
}
}