์ฌ์ฌ ์บก๋๊ฐ ๋๋๊ฐ๋ค..
์๊ฐ์ด ๋จ์์ ์ฝ์ง ์์ฒญํ๋ ๋ถ๋ถ์ ์ ๋ฆฌํด๋ณด๋ ค๊ณ ํ๋ค.
Alamofire ๊น ์ฃผ์
https://github.com/Alamofire/Alamofire
์ฒ์์ ํท๊ฐ๋ ธ๋๊ฒ ๋์์์ ์ด๋ค ํ์์ผ๋ก ์ ์ฅํด์ ๋๊ฒจ์ผํ๋์ง ์ ๋ชฐ๋์๋ค.
URLํ์์ผ๋ก ๋๊ธฐ๋๊น ์ ๋๊ฒจ์ก๋ค.
์ฐธ๊ณ ๋ก ๋์์์ ์จ๋ฒ์์ ๊ฐ์ ธ์์ ์ ์ฅํ๋ค. (์ด ๋ถ๋ถ ์ฝ๋๋ ์๋ตํจ)
import Alamofire
class ViewController: UIViewController {
//๋์์ ์ ์ฅ
var videoURL: URL?
//๋ฒํผ ํด๋ฆญํ๋ฉด ์๋ฒ๋ก ๋์์ ์ ์ก
@IBAction func reportButtonClicked(_ sender: UIBarButtonItem) {
do {
print("videoURL : \(videoURL!)")
uploadImage(imageURL: videoURL!)
} catch {
}
}
}
}
//๋์์ ์๋ฒ๋ก ์ ๋ฌํด์ฃผ๋ ์ฝ๋
func uploadImage(imageURL: URL?) {
let URL = "http://127.0.0.1:8000/uploadfiles"
let header : HTTPHeaders = [
"Content-Type" : "application/json"]
AF.upload(multipartFormData: { multipartFormData in
multipartFormData.append(imageURL!, withName: "files", fileName: "video.mp4", mimeType: "video/mp4")
}, to: URL, usingThreshold: UInt64.init(), method: .post, headers: header).response { response in
guard let statusCode = response.response?.statusCode,
statusCode == 200
else { return }
}
}
ํ์ด์ฌ ์ฝ๋
from fastapi import FastAPI, File, UploadFile
from typing import List
import os
app = FastAPI()
@app.get("/")
def read_root():
return { "Hello": "World" }
@app.post("/uploadfiles")
async def create_upload_files(files: List[UploadFile] = File(...)):
print('here')
UPLOAD_DIRECTORY = "./"
for file in files:
contents = await file.read()
with open(os.path.join(UPLOAD_DIRECTORY, file.filename), "wb") as fp:
fp.write(contents)
print(file.filename)
return {"filenames": [file.filename for file in files]}
@app.post("/files/")
async def create_files(files: List[bytes] = File(...)):
return {"file_sizes": [len(file) for file in files]}
'iOS > Swift' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[iOS/Swift] Image ๋คํฌ๋ชจ๋ ๋์ํ๊ธฐ (0) | 2022.11.23 |
---|---|
[Swift] UI ๊ตฌํ ์ Storyboard์ Code Base ๋น๊ต (0) | 2022.10.26 |
[iOS/Swift] ์นด๋ฉ๋ผ๋ก ๋์์ ์ดฌ์ํ๊ธฐ (0) | 2022.05.21 |
[iOS] Charts ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค์น๋ฐฉ๋ฒ ๋ฐ ์ฌ์ฉ๋ฐฉ๋ฒ (0) | 2022.03.03 |
[iOS] Swift ๋ผ์ด๋ธ๋ฌ๋ฆฌ typing animation (0) | 2021.08.23 |