-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 업로드용 메서드 구현 #197
feat: 업로드용 메서드 구현 #197
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
업로드 메소드만 있는 걸로 확인하고 approve하겠습니다. 👍
// 이미지 업로드용 | ||
func upload(data: Data, to url: String, method: HTTPMethod = .PUT) async throws -> Data { | ||
guard let url = URL(string: url) else { throw NetworkError.components } | ||
var request = URLRequest(url: url, cachePolicy: .reloadIgnoringLocalCacheData) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저희 API중에 cache를 리턴하는 api가 있나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
URL Loading System은 내부적으로 응답에 대해 캐싱을 하는데요,
업로드 메서드 같은 경우 매번 요청에 대한 응답을 받는 것을 보장시키기 위해 저런 cachePolicy 정책을 지정했습니다.
func backgroundUpload(fromFile: URL, | ||
to url: String, | ||
method: HTTPMethod = .PUT, | ||
sessionTaskDelegate: URLSessionTaskDelegate? = nil, | ||
delegateQueue: OperationQueue? = nil) async throws -> Data { | ||
guard let url = URL(string: url) else { throw NetworkError.components } | ||
var request = URLRequest(url: url, cachePolicy: .reloadIgnoringLocalCacheData) | ||
request.httpMethod = method.rawValue | ||
let backgroundSession = URLSession(configuration: .background(withIdentifier: UUID().uuidString), | ||
delegate: sessionTaskDelegate, | ||
delegateQueue: delegateQueue) | ||
let (data, response) = try await backgroundSession.upload(for: request, fromFile: fromFile) | ||
try self.checkStatusCode(of: response) | ||
return data | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아직 observing이나 다른 부분들은 남은거죠?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
위에 적었듯이 URLSessionTaskDelegate로 observing 할 수 있습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아 여기에 업로드 메소드 호출하는 객체를 주입해서 쓰면 되는거군요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵. interactor나 worker에 delegate 채택해서 보내면 될 것 같습니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수고하셨습니다 🎀
🧑🚀 PR 요약
📌 변경 사항
Note
백그라운드 업로드 메서드 사용법
이는 URLSessionTaskDelegate의 didSendBodyData 인자가 있는 메서드를 통해 구현할 수 있습니다.
OperationQueue.main을 넘기면 될 것 같네요
Linked Issue
close #187