Plateformes
Applications mobiles
iOS, Android, Flutter et React Native, via votre backend.
Les exemples de code, les points de terminaison et les codes d'erreur sont identiques dans tous les langages.
Les applications iOS, Android, Flutter et React Native font appel à votre backend, et votre backend fait appel à TryOnCloud. N'intégrez jamais la clé API dans l'application : n'importe qui peut l'extraire du fichier d'installation de l'application.
POST /try-on (photo + product image URL)
POST /api/v1/generate (X-API-KEY)
200 image/png
200 image/png
Créez le point de terminaison backend à l'aide de Node.js, Python ou PHP. Appelez-le ensuite depuis l'application :
React Native
const form = new FormData()
form.append("person", { uri: photo.uri, name: "person.jpg", type: "image/jpeg" })
form.append("garmentUrl", product.imageUrl)
const res = await fetch("https://api.yourapp.com/try-on", { method: "POST", body: form })
// Show the result: save the PNG with expo-file-system or react-native-fs, then render it.Flutter
final req = http.MultipartRequest('POST', Uri.parse('https://api.yourapp.com/try-on'))
..files.add(await http.MultipartFile.fromPath('person', photo.path))
..fields['garmentUrl'] = product.imageUrl;
final res = await http.Response.fromStream(await req.send());
if (res.statusCode == 200) {
setState(() => resultBytes = res.bodyBytes); // Image.memory(resultBytes!)
}Swift (iOS)
var req = URLRequest(url: URL(string: "https://api.yourapp.com/try-on")!)
req.httpMethod = "POST"
req.timeoutInterval = 120
// Build a multipart body with "person" (JPEG data) and "garmentUrl", then:
let (data, response) = try await URLSession.shared.upload(for: req, from: body)
if (response as? HTTPURLResponse)?.statusCode == 200 { image = UIImage(data: data) }Kotlin (Android)
val body = MultipartBody.Builder().setType(MultipartBody.FORM)
.addFormDataPart("person", "person.jpg", photoFile.asRequestBody("image/jpeg".toMediaType()))
.addFormDataPart("garmentUrl", product.imageUrl)
.build()
val request = Request.Builder().url("https://api.yourapp.com/try-on").post(body).build()
client.newCall(request).execute().use { res -> if (res.isSuccessful) bitmap = BitmapFactory.decodeStream(res.body!!.byteStream()) }Définissez le délai d'expiration HTTP sur au moins 120 secondes ; un essai dure environ 20 secondes.
Sur les réseaux mobiles peu fiables, faites envoyer par votre backend une Idempotency-Key pour chaque essai afin qu'une nouvelle tentative ne soit jamais facturée deux fois, ou utilisez une tâche asynchrone et prévenez l'application (par exemple par une notification push) à l'arrivée du webhook generation.completed.