-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from imagekit-developer/develop
SDK enhancements
- Loading branch information
Showing
42 changed files
with
1,641 additions
and
1,545 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// Constants.swift | ||
// ImageKit_Example | ||
// | ||
// Created by Animesh Verma on 06/06/24. | ||
// Copyright © 2024 CocoaPods. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
//Replace with ImageKit public key from ImageKit Dashboard (https://imagekit.io/dashboard/url-endpoints) | ||
let IK_PUBLIC_KEY = "IK_PUBLIC_KEY" | ||
|
||
//Replace with ImageKit URL endpoint (or CNAME) from ImageKit Dashboard (https://imagekit.io/dashboard/url-endpoints) | ||
let IK_URL_ENDPOINT = "https://ik.imagekit.io/IMAGEKIT_ID" | ||
|
||
//Replace with your custom server endpoint to get auth token for uploads | ||
let AUTH_SERVER_API_ENDPOINT = "AUTH_SERVER_API_ENDPOINT" | ||
|
||
//Replace with any image available in your ImageKit media library | ||
let SAMPLE_IMAGE = "default-image.jpg" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// | ||
// UploadAuthService.swift | ||
// ImageKit_Example | ||
// | ||
// Created by Animesh Verma on 25/09/23. | ||
// Copyright © 2023 CocoaPods. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
class UploadAuthService { | ||
static let dispatchGroup = DispatchGroup() | ||
|
||
static func getUploadToken(payload: [String : String]) -> [String : String]? { | ||
let urlSession = URLSession(configuration: URLSessionConfiguration.default, delegate: URLSession.shared.delegate, delegateQueue: URLSession.shared.delegateQueue) | ||
var request = URLRequest(url: URL(string: AUTH_SERVER_API_ENDPOINT)!) | ||
request.httpMethod = "POST" | ||
request.setValue("application/json", forHTTPHeaderField: "Content-Type") | ||
var tokenResponse: [String : String]? = nil | ||
guard let body = try? JSONSerialization.data(withJSONObject: ["uploadPayload": payload, "expire": 60, "publicKey": IK_PUBLIC_KEY] as [String : Any]) else { | ||
return nil | ||
} | ||
request.httpBody = body | ||
dispatchGroup.enter() | ||
DispatchQueue.global().async { | ||
let task = urlSession.dataTask(with: request) { data, response, error in | ||
guard error == nil else { | ||
dispatchGroup.leave() | ||
print(error) | ||
return | ||
} | ||
let response = response as! HTTPURLResponse | ||
let status = response.statusCode | ||
guard (200...299).contains(status) else { | ||
dispatchGroup.leave() | ||
return | ||
} | ||
if let data = data { | ||
tokenResponse = try? (JSONSerialization.jsonObject(with: data) as! [String : String]) | ||
} | ||
dispatchGroup.leave() | ||
} | ||
task.resume() | ||
} | ||
dispatchGroup.wait() | ||
return tokenResponse | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.