I want to use remove.bg's api in my app. I made a request through python and it works, but I do not know how to transfer this to appinventor. My python code and the file I used are attached.
edit: I am not sure whether the image I found online can be used for free, so I removed it.
Thank you for replying. I got the image from a google search. A reverse image search and some checking on getty images tells me that it's free for non commercial use. On the api's website, I found both node JS and java code. I will post both as I am not sure which is better for this situation.
java
// Requires "Apache HttpComponents" to be installed (see hc.apache.org)
Response response = Request.Post("https://api.remove.bg/v1.0/removebg")
.addHeader("X-Api-Key", "INSERT_YOUR_API_KEY_HERE")
.body(
MultipartEntityBuilder.create()
.addBinaryBody("image_file", new File("/path/to/file.jpg"))
.addTextBody("size", "auto")
.build()
).execute();
response.saveContent(new File("no-bg.png"));
I have tried to use the post block in the web component, but I only get a 404 error. So either I am doing something wrong, or it just does not work.
As for Dwayne, the getty images site was not very clear whether I could use the image. I got this info from their help center. For now I will use another image
Using images for free
The images on Getty Images are intended for use in commercial and editorial projects. This means you need to buy a license to use the image in most projects, including personal use.
You can use an image without paying for a license with our Embed feature, which lets you use over 70 million photos on any non-commercial website or blog (if you're using it to sell a product, raise money or promote or endorse something, Embed isn't for you). Just do a search, then go to Filters to turn on the Embeddable images filter on the search results page.
If you post you test code here, someone who knows more about it than me can help you. Probably the critical issue is where the image is stored and where the modified image should be stored. Possibly only an Android shared directory can be used.
the image above is the code I used. As far as I know, when the image is returned, setting the image1.picure to the filename variable should work, assuming there is an image there. @ChrisWard Thank you for your help!
The gotfile event does not trigger at all, but the gottext event returns Do It Result: Do It Result: "< !DOCTYPE html >
< html lang="en" >
< head >
< meta charset="utf-8" >
< title > Error < /title >
< /head >
< body >
< pre >Cannot POST /v1.0/removebg/image_file=dwayne.jpg< /pre >
< /body >
< /html >
Right - that's a private directory, anything outside of the App cannot access it, so that is probably the first hurdle that the Cannot Post message is moaning about.
So the image needs to be in Shared Storage '/Pictures' and likely requires the full path to it: