Page 1 of 1

I cannot use the input-document API, please advise

Posted: Mon Nov 09, 2015 7:02 am
by danmarina
Hi,
I need some help with uploading a document as input document via API as described in the PHP example at this link: http://wiki.processmaker.com/REST_API_C ... t-document

No matter what I'm doing, I keep getting the error: 400, Bad Request: This filename does not exist!.
When looking into the PM classes seems like the $_FILES is always empty. I'm new to APIs, I have no idea how debug further.

Please, let me know if anyone managed to use that piece of code to post an input-document (from another machine).

regards,
/d.

Re: I cannot use the input-document API, please advise

Posted: Sun May 15, 2016 2:39 am
by Mohinish
Hi Danmarina ,

I'm also facing same issue.Can you advice me solution ,if you got solution of that issue.
Me also posted on forum Topic How to upload file while creating case using REST API?

Thanks alot in advance :( :cry:

Re: I cannot use the input-document API, please advise

Posted: Tue May 31, 2016 11:42 pm
by amosbatto
Post your code and maybe someone can help you.

Re: I cannot use the input-document API, please advise

Posted: Wed Jun 01, 2016 6:35 pm
by amosbatto
In PHP you have to place the @ before the path to avoid this error. See the PHP code example.

Re: I cannot use the input-document API, please advise

Posted: Wed Jun 01, 2016 9:59 pm
by amosbatto
I found that PHP 5.5 and later has a problem using @ before the path. Instead, you have to use a CurlFile() object. I have updated the documentation. See: http://wiki.processmaker.com/REST_API_C ... t-document

Re: I cannot use the input-document API, please advise

Posted: Sun Jun 05, 2016 8:58 am
by Mohinish
Hi Amosbatto,

I'm using asp.net for saving file and passing path as parameter.
like:-
{
"inp_doc_uid":"test10111124322509756bc1b5test10",
"tas_uid": "24322509756bc1b5012c202012716621",
"app_doc_comment": "test",
"form":"workflow/public_html/test.txt"
}

Response:- "message": "Bad Request: This filename does not exist!"

Can you suggest me ,what's the issue and how to solve? Please.....
Thanks

Re: I cannot use the input-document API, please advise

Posted: Mon Jun 06, 2016 9:42 pm
by amosbatto
Mohinish,
Your "form" needs to be a file location on the machine executing the code. Web URLs do not work. If you want to use a web URL, you need to download the file and save it to a local file, which can then be uploaded to REST.

Re: I cannot use the input-document API, please advise

Posted: Tue Jun 07, 2016 11:18 am
by Mohinish
Hi Amosbatto,

Thank You for great Support.

Re: I cannot use the input-document API, please advise

Posted: Thu Jun 09, 2016 7:36 am
by Mohinish
Hi,

I'm uploading file by using REST API while posting everything is fine but request status is 302 Found.
Please find attached Screen shot for API Request.
Post Data.png
Post Data.png (28 KiB) Viewed 19396 times
Post Data are below:-
--------------------------------------------------------------------------------------------
-----------------------------71042153412624
Content-Disposition: form-data; name="0"; filename="Capture.PNG"
Content-Type: image/png

‰PNG

���
IHDR��A��c���ãÕÓ���sRGB�®Îé���gAMA��±üa���
-----------------------------71042153412624
Content-Disposition: form-data; name="inp_doc_uid"

test10111124322509756bc1b5test10
-----------------------------71042153412624
Content-Disposition: form-data; name="tas_uid"

24322509756bc1b5012c202012716621
-----------------------------71042153412624
Content-Disposition: form-data; name="app_doc_comment"

test
-----------------------------71042153412624--

---------------------------------------------------------------------------------------------
After That i'm not receiving any Response
& Request Status 302 Found.
Can anyone help in that?

Thanks You

Re: I cannot use the input-document API, please advise

Posted: Thu Jun 09, 2016 8:39 pm
by amosbatto
A status code of 302 usually means URL redirection. See: https://en.wikipedia.org/wiki/HTTP_302
I know nothing about asp.net, but this article might help you: http://www.c-sharpcorner.com/UploadFile ... t-web-api/

Re: I cannot use the input-document API, please advise

Posted: Tue Sep 26, 2017 12:02 pm
by FelipeSolis
Hi, I'm facing this problem with .NET too. API always return file does not exist. I would like to know if there is another way to upload the file input

Re: I cannot use the input-document API, please advise

Posted: Tue Sep 26, 2017 9:09 pm
by amosbatto
FelipeSolis wrote:Hi, I'm facing this problem with .NET too. API always return file does not exist. I would like to know if there is another way to upload the file input
Are you trying to use a web uploader like this or are you trying to run a script which uploads a file which already exists on the computer? Post your code. I don't know anything about .NET, but maybe I can spot something if I look at your code.

Re: I cannot use the input-document API, please advise

Posted: Wed May 29, 2019 2:29 pm
by jdcrain
You can upload documents by using MultipartFormDataContent in C#. This was all done in ASP.Net Core, but it should work for some of the older .Net MVC versions as well.
Code: Select all
public async Task<ActionResult<JObject>> UploadFile()
{
        using (HttpClient client = new HttpClient())
        using (var formData = new MultipartFormDataContent())
        {
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer",  authToken);

            formData.Add(new StringContent(documentUid), "inp_doc_uid");
            formData.Add(new StringContent(taskUid), "tas_uid");
            formData.Add(new StringContent(documentComment), "app_doc_comment");

            string filePath = Path.GetFullPath("/path/to/file.jpg");
            FileStream fileStream = new FileStream(filePath, FileMode.Open);

            formData.Add(new StreamContent(fileStream), "form", "file.jpg");

            HttpResponseMessage response = await client.PostAsync("https://example.com/api/1.0/workspace/cases/{caseId}/input-document", formData);

            string responseString = await response.Content.ReadAsStringAsync();

            JObject responseJson = JObject.Parse(responseString);

            if (!response.IsSuccessStatusCode)
            {
                return StatusCode((int)response.StatusCode, responseString ?? response.ToString());
            }

            return Ok(responseJson);
        }
}
You can also check out this Stackoverflow answer if you need to work with the file bytes rather than the file stream. https://stackoverflow.com/a/19983672

Re: I cannot use the input-document API, please advise

Posted: Wed May 29, 2019 8:53 pm
by amosbatto
I also added a REST endpoint for uploading files which you might find useful:
https://www.pmusers.com/index.php/Extra ... D.2Fupload