File tree 2 files changed +58
-0
lines changed
2 files changed +58
-0
lines changed Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html >
3
+ < head >
4
+ < title > 이미지 업로드</ title >
5
+ < script src ="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js "> </ script >
6
+ </ head >
7
+ < body >
8
+ < h1 > 이미지 업로드</ h1 >
9
+ < input type ="file " id ="imageInput ">
10
+ < button onclick ="uploadImage() "> 이미지 업로드</ button >
11
+
12
+ < script >
13
+ function uploadImage ( ) {
14
+ var input = document . getElementById ( 'imageInput' ) ;
15
+ var image = input . files [ 0 ] ;
16
+ var file = new FormData ( ) ;
17
+ file . append ( 'file' , image ) ;
18
+ console . log ( "formData : %o" , file ) ;
19
+ var requestOptions = {
20
+ method : 'POST' ,
21
+ body : file ,
22
+ redirect : 'follow'
23
+ } ;
24
+
25
+ axios . post ( 'http://127.0.0.1:8000/photo' , file )
26
+ . then ( function ( response ) {
27
+ // 업로드에 성공한 경우
28
+ console . log ( response . data ) ;
29
+ // 응답 데이터를 처리하거나 화면에 표시합니다.
30
+ } )
31
+ . catch ( function ( error ) {
32
+ // 업로드에 실패한 경우
33
+ console . log ( "에러네.." ) ;
34
+ console . log ( error ) ;
35
+ // 에러 처리 로직을 추가합니다.
36
+ } ) ;
37
+ }
38
+ </ script >
39
+ </ body >
40
+ </ html >
Original file line number Diff line number Diff line change 4
4
from PIL import Image
5
5
import torch
6
6
import os
7
+ from fastapi .middleware .cors import CORSMiddleware
7
8
8
9
from loguru import logger
9
10
10
11
11
12
model = torch .load ('shufflenet_weight.pt' , map_location = torch .device ('cpu' ))
12
13
14
+
13
15
app = FastAPI ()
14
16
17
+ origins = [
18
+ "*"
19
+ ]
20
+
21
+ app .add_middleware (
22
+ CORSMiddleware ,
23
+ allow_origins = origins ,
24
+ allow_credentials = True ,
25
+ allow_methods = ["*" ],
26
+ allow_headers = ["*" ],
27
+ )
28
+
15
29
16
30
@app .post ("/photo" )
17
31
async def create_upload_file (file : UploadFile = File (...)):
@@ -28,6 +42,10 @@ async def create_upload_file(file: UploadFile = File(...)):
28
42
# image = ToTensor()(Image.open(file.file))
29
43
# output = model(image)
30
44
# logger.info("Classify Result = {}", output)
45
+ print ({
46
+ "content_type" : file .content_type ,
47
+ "filename" : file .filename
48
+ })
31
49
return {
32
50
"content_type" : file .content_type ,
33
51
"filename" : file .filename
You can’t perform that action at this time.
0 commit comments