S samperizal Active Member Licensed User Longtime User Apr 3, 2024 #1 Greetings. I want to use a web api (Tested with postman and c#). This has two parameters, a file and a token. The file does not reach the webapi. This is the code I am using. [CODE lang="b4x" title="Code"] Dim URL As String = "https://a373-84-79-160-209.ngrok-free.app/Reconocimiento/Reconocer" Dim j As HttpJob j.Initialize("", Me) Dim fd As MultipartFileData fd.Initialize fd.KeyName = "file" fd.Dir = File.DirDefaultExternal fd.FileName = "ejemplo.jpg" fd.ContentType = "image/jpg" j.PostMultipart(URL, CreateMap("Token": "1234"),Array(fd)) Wait For (j) JobDone(j As HttpJob) If j.Success Then Leer_Json_Respuesta_json (j.GetString) Else Log ("error") Log(j.ErrorMessage) Log(LastException) End If j.Release[/CODE] Thank you.
Greetings. I want to use a web api (Tested with postman and c#). This has two parameters, a file and a token. The file does not reach the webapi. This is the code I am using. [CODE lang="b4x" title="Code"] Dim URL As String = "https://a373-84-79-160-209.ngrok-free.app/Reconocimiento/Reconocer" Dim j As HttpJob j.Initialize("", Me) Dim fd As MultipartFileData fd.Initialize fd.KeyName = "file" fd.Dir = File.DirDefaultExternal fd.FileName = "ejemplo.jpg" fd.ContentType = "image/jpg" j.PostMultipart(URL, CreateMap("Token": "1234"),Array(fd)) Wait For (j) JobDone(j As HttpJob) If j.Success Then Leer_Json_Respuesta_json (j.GetString) Else Log ("error") Log(j.ErrorMessage) Log(LastException) End If j.Release[/CODE] Thank you.
JohnC Expert Licensed User Longtime User Apr 3, 2024 #2 ChatGPT suggestes try changing the line: B4X: fd.ContentType = "image/jpg" 'to fd.ContentType = "image/jpeg" Upvote 0
ChatGPT suggestes try changing the line: B4X: fd.ContentType = "image/jpg" 'to fd.ContentType = "image/jpeg"
JohnC Expert Licensed User Longtime User Apr 3, 2024 #4 As a test, I would also try moving the source file from "File.DirDefaultExternal" to "File.DirInternal" just in case your app/device doesn't allow permission to access .DirDefaultExternal Last edited: Apr 3, 2024 Upvote 0
As a test, I would also try moving the source file from "File.DirDefaultExternal" to "File.DirInternal" just in case your app/device doesn't allow permission to access .DirDefaultExternal
S samperizal Active Member Licensed User Longtime User Apr 3, 2024 #5 the file does not arrive Upvote 0
MicroDrie Well-Known Member Licensed User Longtime User Apr 3, 2024 #6 samperizal said: the file does not arrive Click to expand... Well, I ran into a similar challenge . When you go to the web page https://a373-84-79-160-209.ngrok-free.app/Reconocimiento/Reconocer for the first time, you must first click on the "Visite site" button. When a cookie is placed in your browser with your visit time in it. How does your program ensure that it uses the cookie consent function "you first click on the Visit Site to go on" button ? If that doesn't happen, then (just like it was the case with me) it will be an endless wait. Upvote 0
samperizal said: the file does not arrive Click to expand... Well, I ran into a similar challenge . When you go to the web page https://a373-84-79-160-209.ngrok-free.app/Reconocimiento/Reconocer for the first time, you must first click on the "Visite site" button. When a cookie is placed in your browser with your visit time in it. How does your program ensure that it uses the cookie consent function "you first click on the Visit Site to go on" button ? If that doesn't happen, then (just like it was the case with me) it will be an endless wait.
MicroDrie Well-Known Member Licensed User Longtime User Apr 3, 2024 #7 My workaround is not pretty, but it works by first visiting the site in web view, giving consent (the site places a cookie in the web view environment) and leaving out the consent cookie wall. So what you are looking for is a way to give permission with a B4A/B4J program so that the cookie is placed and the cookie wall is omitted. Upvote 0
My workaround is not pretty, but it works by first visiting the site in web view, giving consent (the site places a cookie in the web view environment) and leaving out the consent cookie wall. So what you are looking for is a way to give permission with a B4A/B4J program so that the cookie is placed and the cookie wall is omitted.
aeric Expert Licensed User Longtime User Apr 3, 2024 #8 samperizal said: j.PostMultipart(URL, CreateMap("Token": "1234"),Array(fd)) Click to expand... try: B4X: Dim Map1 As Map = CreateMap("Token": "1234") Dim List1 As List List1.Initialize List1.Add(fd) j.PostMultipart(URL, Map1, List1) Upvote 0
samperizal said: j.PostMultipart(URL, CreateMap("Token": "1234"),Array(fd)) Click to expand... try: B4X: Dim Map1 As Map = CreateMap("Token": "1234") Dim List1 As List List1.Initialize List1.Add(fd) j.PostMultipart(URL, Map1, List1)
S samperizal Active Member Licensed User Longtime User Apr 5, 2024 #9 Greetings. Still not uploading the file. I have made a routine in c# and it works correctly and the same in postman. Upvote 0
Greetings. Still not uploading the file. I have made a routine in c# and it works correctly and the same in postman.
aeric Expert Licensed User Longtime User Apr 5, 2024 #10 Is your server online and do you have sample B4A project? Upvote 0
Andrew (Digitwell) Well-Known Member Licensed User Longtime User Apr 7, 2024 #11 Can you provide a postman file of a working connection? Upvote 0
S samperizal Active Member Licensed User Longtime User Apr 9, 2024 #12 Solved. Change fd.ContentType = "image/jpg" to fd.ContentType="multipart/form-data" Upvote 0