No matter what i try i always get a BadRequest or if i try the C# example code i get UriString to long errors. Passing a base64 image through the query string is a really weird concept in my opinion.
If i post it as x-www-form-urlencoded i get 400, if i post it as json i get 400… Any tips are welcome.
아래에 의견을 추가하고 토론에 참여하세요.
}
same errror in flutter tried json encode decode
Future<String> removeBG(String imageUrl) async {
final response = await http.post(
Uri.parse(‘https://background-removal.p.rapidapi.com/remove’),
headers: {
“content-type”: “application/x-www-form-urlencoded”,
“X-RapidAPI-Key”: “–”,
“X-RapidAPI-Host”: “background-removal.p.rapidapi.com”
}
Hi Dylan,
Sorry for our late reply, we haven’t get any notification from this discussion thread.
I think the problem, based on the piece of code attached, that you are trying the send the image itself without any encoding (so, the image in bytes). Our API only supports, at least for now, the way of sending an image using a public URL or encoding it in base64 and sending over as a string.
The process that you should follow in case you want to use ObjectCut is to get the file that you want to process, encode it in base64 and sending that using the
image_base64
form field as a string. If you send the image itself (in bytes) the API is gonna return you a 400 status code because it doesn’t fit with the input requirements.I found this StackOverflow post that you could be useful for your integration: https://stackoverflow.com/questions/21325661/convert-an-image-selected-by-path-to-base64-string
If you are still having problems, let us know and we are gonna try to help you.
Thanks and sorry for the inconvenience.
Keep in touch.
Regards,
ObjectCut team.
Hi,
Thank you for your reply.
I really didn’t get this to work with plain .NET Core. The example code complained about to long UriString or gave ‘BadRequest’ errors, without explanation.
I tried with an image of 800kb i think, maybe this is to large.
Anyway, after searching on google i ended up on https://imagezerow.com/#/ which is a different version of RapidAPI?
https://rapidapi.com/imagezero-imagezero-default/api/image-background-removal-v2/details
Here i am able to do a file upload with the following code.
` public static async Task<Bitmap> RemoveBackgroundFromImage(Bitmap bitmap)
{
var url = “rapidapi.url”;
If this same approach is possible with this API you can add my code as .NETCore C# version.
Hi Dylan,
Thanks for your question. I’m trying to reproduce your error in my end but I’m always getting a successful response. HTTP 400 status codes are usually meaning that some parameters were incorrectly introduced and/or the parameter type is not the expected. Which data type are you passing over for the
image_base64
field? Is it string?Also, for your information, ObjectCut API only supports POST methods and x-www-form-urlencoded data type for the request body.
This is a C# example generated by the RapidAPI tool that worked for me:
I assume you can only pass a url of an online image and not post the image? That would really be a constraint 😦