Cartoon yourself

FREEMIUM
Por AILabTools | Actualizada vor 7 Tagen | Artificial Intelligence/Machine Learning
Popularidad

9 / 10

Latencia

3,843ms

Nivel de servicio

98%

Health Check

100%

Volver a todas las conversaciones

image cannot both be empty

Rapid account: Rezasouri
rezasouri
vor einem Jahr

Hi there
I all the times receiving above error, no matter what image type I use(BMP, PNG, JPEG,JPG)
below is my code that I try to call API
Can you help me please?

<!DOCTYPE html>
<html>
<head>
<script src=“https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js”></script>
</head>
<body>
<input type=“file” id=“input” onchange=“loadFile(event)”>
<script>
function loadFile(event) {
const file = event.target.files[0];
const reader = new FileReader();
reader.onload = (e) => {
const data = new FormData();
data.append(“image”, e.target.result);
data.append(“type”, “pixar”);
const options = {
method: ‘POST’,
url: ‘https://cartoon-yourself.p.rapidapi.com/facebody/api/portrait-animation/portrait-animation’,
headers: {
‘X-RapidAPI-Key’: ‘cce40d4004msh10d9f941cac0181p1e3409jsn8d5fe248c534’,
‘X-RapidAPI-Host’: ‘cartoon-yourself.p.rapidapi.com
},
data: data
};
axios.request(options)
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.error(error);
});
}
reader.readAsDataURL(file);
}
</script>
</body>
</html>

Rapid account: Muhammadadil 661998
muhammadadil661998 Commented vor einem Jahr

can I used custom cartoon?
Please Help

Rapid account: Zhou Wenxiang
ZhouWenxiang Commented vor einem Jahr

@support-vJevsTtR-tQ

Please confirm the data passed in the [image] field, which receives the binary stream data of the image.
and whether the [imageData] field you defined carries the correct data.

You can refer to the official sample code provided by rapidapi.

Rapid account: Support V Jevs Tt R T Q
support-vJevsTtR-tQ Commented vor einem Jahr

Getting same issue with Swift.

Can you please help :

class APIHandler{

func convertImage(inputImage: UIImage, style: Style, completion: @escaping (_ outputImage: UIImage) -> ()) {

    let headers = [
        "content-type": "multipart/form-data; boundary=---011000010111000001101001",
        "X-RapidAPI-Key": "***",
        "X-RapidAPI-Host": "cartoon-yourself.p.rapidapi.com"
    ]
    
    let imageData = inputImage.pngData()!
    
    let parameters = [
        [
            "name": "image",
            "fileName": "image.png",
            "contentType": "application/octet-stream",
            "file": imageData
        ],
        [
            "name": "type",
            "value": "angel"
        ]
    ]

    let boundary = "---011000010111000001101001"

    var body = Data()
    for param in parameters {
        let paramName = param["name"]!
        let boundaryPrefix = "--\(boundary)\r\n".data(using: .utf8)
        let contentDisposition = "Content-Disposition:form-data; name=\"\(paramName)\"".data(using: .utf8)
        body.append(boundaryPrefix!)
        body.append(contentDisposition!)

        if let fileName = param["fileName"] {
            let contentType = param["contentType"]!
            let contentTypeValue = "Content-Type: \(contentType)\r\n\r\n".data(using: .utf8)
            body.append(contentTypeValue!)
            body.append(imageData)
        } else if let paramValue = param["value"] {
            let value = "\r\n\r\n\(paramValue)".data(using: .utf8)
            body.append(value!)
        }
    }
    let boundarySuffix = "--\(boundary)--\r\n".data(using: .utf8)
    body.append(boundarySuffix!)

  
    let request = NSMutableURLRequest(url: NSURL(string: "https://cartoon-yourself.p.rapidapi.com/facebody/api/portrait-animation/portrait-animation")! as URL,
                                            cachePolicy: .useProtocolCachePolicy,
                                        timeoutInterval: 10.0)
    request.httpMethod = "POST"
    request.allHTTPHeaderFields = headers
    request.httpBody = body

    let session = URLSession.shared
    let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
        if (error != nil) {
            print(error)
        } else {
            let httpResponse = response as? HTTPURLResponse
            
            do {
                let jsonDictionary = try JSONSerialization.jsonObject(with: data!, options: []) as? [String: Any]
                print(jsonDictionary!)
            } catch {
                print(error)
            }
            
            print(httpResponse)
            if let outputImage = UIImage(data: data!) {
                    completion(outputImage)
                }
        }
    })

    dataTask.resume()
    
    
}

}

Rapid account: AI Lab Tools Group
AILabToolsGroup Commented vor einem Jahr

Sorry, the message window of rapidapi was not fully displaying the message, which caused me not to see your code, now I see it, your problem was that you converted the file to base64 to send it, hence the error, you can just use file without converting to base64, the correct code is as follows.

Also note that it is dangerous not to expose your X-RapidAPI-Key here, you can edit your post to change the X-RapidAPI-Key.

function loadFile(event) {
  const file = event.target.files[0];
  const data = new FormData();
  data.append("image", file);
  data.append("type", "pixar");
  const options = {
    method: 'POST',
    url: 'https://cartoon-yourself.p.rapidapi.com/facebody/api/portrait-animation/portrait-animation',
    headers: {
      'X-RapidAPI-Key': 'xxxxxxxx',
      'X-RapidAPI-Host': 'cartoon-yourself.p.rapidapi.com'
    },
    data: data
  };

  axios.request(options)
    .then(function (response) {
      console.log(response.data);
    })
    .catch(function (error) {
      console.error(error);
    });
}

Únase a la conversación, añada un comentario a continuación:

Inicie sesió/Regístrese para publicar nuevos comentarios